First in my servlet I was using a Image-Servlet jar from some blog, my images were working fine. But the problem was any one can use inspect element and append the url with ../
to get to other directories also which was a big security problem. So I asked a question on SO, people suggested to make my own code as it was easy and I could have full control.
So here is my code,
String path1=getServletConfig().getServletContext().getRealPath("");
System.out.println(path1); // /usr/share/tomcat7/webapps/myProject
String l = File.separator;
f = new File(path1+l+"images"+l+"load.gif");
BufferedImage bi = ImageIO.read(f);
OutputStream out = response.getOutputStream();
ImageIO.write(bi, "gif", out);
out.close();
It works good, but the problem is the image dont animate any more. I tried downloading it and opened it but it was not animating.
So I guess during reading the file into bufferedImage something changed.
the images looks like these
You can see in inspect element or source that both are gif but only one is animating