Hi,
I was just attempting to solve the same problem for myself. I found a nice
piece of code in the archives that uses the class loader to find my files
and gives me an input stream. I am using it for finding property files but
there is no reason why it won't work for reading an HTML template.
ClassLoader cl = getClass().getClassLoader();
InputStream propInputStream = null;
String resourceName = "QFSecurity.properties";
System.out.println("Resource name: " + resourceName);
if (cl != null) {
propInputStream = cl.getResourceAsStream(resourceName);
}
if (propInputStream == null) {
//attempt to get the stream from the classpath
propInputStream =
ClassLoader.getSystemResourceAsStream(resourceName);
}
if (propInputStream == null) {
//prop file is unretrievable
String msg = "unable to locate property resource: "
+ resourceName;
config.getServletContext().log("[Initialization
Error] " + msg);
throw new ServletException(msg);
}
at this point, you have an input stream to your file and all you needed to
know was its name and the fact that it is in the classpath somewhere.
John Zerbe - Mellon Bank
Phone: 412-234-1048 E-Mail: [EMAIL PROTECTED]
> -----Original Message-----
> From: John Larson [SMTP:[EMAIL PROTECTED]]
> Sent: Wednesday, May 05, 1999 12:18 PM
> To: [EMAIL PROTECTED]
> Subject: File Paths in Init
>
> 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
>
> __________________________________________________________________________
> _
> 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
___________________________________________________________________________
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