I wanted to display the images inside servlets,
there were many complex methods like
- first dumping images in Database, then using it
- reading from disk and converting to byte array then having separate servlet for each image
Then finally I found this very easy.
I used Image Servlet from this tutorial
changed the web.xml
<servlet>
<servlet-name>Image</servlet-name>
<servlet-class>com.jsos.image.ImageServlet</servlet-class>
<init-param>
<param-name>dir</param-name>
<param-value>C:/Users/myName/Desktop/myName/workspace_j2ee/myServlet/WebContent/images</param-value>
</init-param>
<init-param>
<param-name>expires</param-name>
<param-value>86400</param-value>
</init-param>
</servlet>
I can successfully display image using
/Myservlet/Image?fileName.png
but the problem is this is actually security hole, as I tried
/Myservlet/Image?../../src/maJavafiles.java
And to my surprise the java files were downloaded. So how can I restrict the user to put this kind of url i mean going on level up in the directory structure