Hello, I have a code which can help you if you are using the servlet for displaying the image. So, make use of it.
Code:
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
{
HttpSession HSession = req.getSession();
ServletContext Servletcon = getServletContext();
String str = Servletcon.getRealPath("1-30.jpg");
String mtype = Servletcon.getMimeType(str);
if (mtype == null)
{
Servletcon.log("Could not get MIME type of"+ str);
resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
return;
}
File file = new File(str);
resp.setContentLength((int)file.length());
FileInputStream in = new FileInputStream(file);
resp.setContentType("image / jpeg" );
BufferedInputStream out2 = new BufferedInputStream(resp.getOutputStream());
byte by[] = new byte[ 32768 ];
int index = in.read( BY, 0, 32768 );
while ( index! = -1 )
{
out2.write( BY, 0, Index );
index = in.read( BY, 0, 32768 );
}
out2.flush();
}
Bookmarks