Where do I store image files so my servlet's HTML pages can display them?
Created May 4, 2012
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:
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.-root
|
-servlet
| |
| *MyServlet
| *TestServlet
|
-images
| |
| *Duke.gif
| *Web.gif
|
-MyHtmlFiles
|
*Main.html
*Login.html
<img src="../images/Duke.gif">
or
<img src=" /images/Duke.gif">