Accessing ServletContext from Startup Actions
"Duane Adams" <[email protected]> Tue, 13 Jul 2004 00:30:55 -0700
| Newsgroups | gmane.comp.java.jpublish.devel |
|---|---|
| Message-ID | <003901c468ab$56085720$9901a8c0@ds9> |
How do i access the ServletContext from a startup action?
I would like to get the full path to a properties file the WEB-INF folder
and make it available to a startup action. Usually in a regular servlet, i
would do something like:
String realPath =
getServletContext().getRealPath("WEB-INF/file.properties")
The user guide suggests that the site object is available to me in a startup
action. So i should be able to do:
ServletContext sc = context.getApplication()
String realPath = sc.getRealPath("WEB-INF/file.properties")
However, the user guide also says that the ServletContext or "application"
is not available to startup actions.
Is their another way to do this? Can the vfs resolve full paths?
Basically, i'm trying to turn this:
public InitSomeServlet extends HttpServlet {
public init(ServletConfig config) {
try{
ServletContext sc = getServletContext()
String realPathToConfig =
sc.getRealPath(config.getInitParameter("config"))
SomeServlet.init(realPathToConfig)
} catch(...){}
}
}
into this (startup action):
public InitSomeServlet implements Action {
public execute(RequestContext context, Configuration config){
try{
ServletContext sc = context.getApplication()
String realPathToConfig =
sc.getRealPath(config.getValue("config"))
SomeServlet.init(realPathToConfig)
} catch(...) {}
}
}
any guidance would be appreciated.
Thanks,
Duane Adams
-------------------------------------------------------
This SF.Net email sponsored by Black Hat Briefings & Training.
Attend Black Hat Briefings & Training, Las Vegas July 24-29 -
digital self defense, top technical experts, no vendor pitches,
unmatched networking opportunities. Visit www.blackhat.com