Where do I store image files so my servlet's HTML pages can display them?

Nicola Ken Barozzi

Anywhere you want [under your server's document root], just remember to use the correct path relative to the one of the servlet.

A servlet is seen by the browser just by its URL. Browsers doesn't see the difference between a file, a servlet or a JSP. Servlets are usually grouped in a directory which is mapped to a directory URL. [You must put the image files in a directory off of the document root, which is not where the servlet class files are, but will probably be near JSP and HTML files. -Alex]

This is what a browser may see:

-root
    |
    -servlet
    |     |
    |     *MyServlet
    |     *TestServlet
    |
    -images
    |     |
    |     *Duke.gif
    |     *Web.gif
    |
    -MyHtmlFiles
          |
          *Main.html
          *Login.html     

Here the servlet and the MyHtmlFiles directory are in the same position relative to the images directory. This means that you should write the link to the image in the servlet as you would in the html files in the MyHtmlFiles directory.
<img src="../images/Duke.gif">
or
<img src=" /images/Duke.gif">
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact