John Larson wrote:
> Hi,
>
> I am reading HTML template files into a string field in the init block
> of my servlet so that the file I/O is done only once. I have specified
> the entire path to the files, starting at the server root level.
> However, if any piece of the path changes, I will need to change my
> servlet code, which is not desirable.
>
> I know that I could pass a startup paramater to the servlet with the
> path, but changing the paramater value is still a manual intervention.
>
> How can I retrieve the server root directory and/or path information
> about my servlet while it is still in the init block?
>
> I have seen several examples of doing this once a request has been
> received, but not before.
>
> Thanks,
> John
>
In a 2.1-compatible servlet engine, you can call ServletContext.getResource()
or ServletContext.getRealPath() in the init() method of your servlet. Note
that there is still going to be manual intervention, because whoever installs
the servlet engine is setting where the "root" paths to these resources and
files really are. But it avoids you having to do it for yourself -- which can
be especially important if you've got lots of servlets that depend on this
kind of thing.
Craig McClanahan
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html