You can still use simple relative URLs. For example, in your servlet, you could
have:

out.println("<IMG src=/images/my_image.gif>");

This will refer to the base directory (the "/"), and then go the images directory.

You could also do something like:

out.println("<A HREF=../docs/my_doc.html>View Docs</A>");

So, if your URL to get to your servlet is
http://myserver.mydomain.com/servlets/MyServlet, the above URL will rewrite to:

http://myserver.mydomain.com/docs/my_doc.html



"Craig R. McClanahan" wrote:

> "Ackerman, Lee" wrote:
>
> > I'm hoping that there is a simple answer to the following:
> >
> > I need to be able to have my servlet generate a dynamic HTML file that
> > references static elements such as a javascript file and an image.  Is there
> > a way to use relative paths to specify where to retrieve these items?  Or do
> > I have to write a servlet that handles the request of the static files?  I
> > have the Servlet book by Jason Hunter and he has a sample servlet that can
> > be used for the retieval of static files - do I have to use something like
> > this in order to have this mix of dynamic and static html?
> >
> > Thanks for you help!
> >
>
> You can easily generate references to static resources in the dynamic HTML code
> that your servlet generates.  The simplest way is to just create URLs that
> contain the absolute path on the web server to where those resources live.
> That way, the web server will serve them like any other file, and the servlet
> does not have to worry about it  The only challenge is, how does your servlet
> know what directory the resources are stored in?
>
> My approach to this is to define an initialization parameter for my servlet
> (for example, called "images.directory") that contains the directory prefix on
> my web site where the images can be found.  Then, in the servlet, I concatenate
> this with the name of the image I want (for example), and that becomes the
> value of the SRC attribute on my IMG tag.  If I ever need to move the images to
> a different directory, only one thing needs to be changed (the initialization
> parameter)  -- I don't have to make any changes to the code that is actually
> generating the links.
>
> >
> > Lee Ackerman
> >
>
> 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

___________________________________________________________________________
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