Yogesh More wrote:

> Firstly, I just finished doing the stuff you asking for ....
>
> What I do is the following
>
> public class HTMLString {
> .....
> ..
> public String getBodyString(String filename)
> {
>       // this loads the .html file from a directory which is a sub-directory
> in which the HTMLString class is
>      //  in your case this will be the servlet class
>      URL fileURL = HTMLString.class.getResource("../html/"+filename);
>
>      InputStream fis = fileURL.openStream();
>      // now read and parse the file from which only the body part is
> returned
>      // ... blah blah .. read into bodyString
>
>     return bodyString;
> }
>

You can also consider using ServletContext.getResource() to accomplish this
objective.  The difference is that you specify a context-relative URL for your
HTML or image file, instead of trying to locate the resource file within your
classpath.  This is especially useful when you are accessing a resource file
that also might be addressed separately from a client browser.

Craig McClanahan


> And secondly, it's not a dumb question ;-) ...
>
> Hope it helps,
> cheers,
> Yogesh
>
> > -----Original Message-----
> > From: Kevin Yancy [SMTP:[EMAIL PROTECTED]]
> > Sent: Sunday, March 12, 2000 3:30 AM
> > To:   [EMAIL PROTECTED]
> > Subject:      Servlet File Access
> >
> > Hi all,
> >
> > I wrote a class that will open a static HTML file and return
> >
> > the <BODY> portion in various formats. The idea is that a
> > servlet could use this class to get all or a portion of it's
> >
> > content from static HTML files.
> >
> > This works, but only if I provide the full path on the local
> >
> > file system where the servlet resides. This of course won't
> > get it. The static HTML files will always be in a
> > subdirectory of where the servlet that accesses them resides
> >
> > (i.e. /myServletDir/content).
> >
> > How can I determine where the servlet was actually loaded so
> >
> > that I can access the files in the "content" subdir by a
> > relative pathname?
> >
> > Apologize in advance if this is a dumb question. I checked
> > the archives but couldn't find the answer :-)
> >
> > thanx
> > Kevin
> >
> > __________________________________________________________________________
> > _
> > 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

___________________________________________________________________________
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

Reply via email to