I want to retrieve image from database which is stored as a blob and this image is a profile image of employee so with image some other details will come like name,designation and all so i am passing servlet path and value in employeedetail.jsp and it is going to that servlet and everything is correct like query , parameter but finally on employeedetail.jsp page image is not coming it is just showing a cross sign there please anyone help me here is code..
Login.Java
public class Login extends HttpServlet {
    public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, java.io.IOException {
        HttpSession session = request.getSession();
        // InputStream sImage;
        String sid = request.getParameter("eid");
        session.setAttribute("sid", sid);
        String password = request.getParameter("password");
        try {
            Connection con = ConnectionManager.getConnection();
            String query = "select eid, name, password, sex, dob, bloodgroup, fathername, qualification, mailid, contactnum, skills, temporaryadd, permanentadd, access_type
            from empinfo where eid = '" + sid+ "' AND password = '" + password + "' ";
            Statement stmt = con.createStatement();
            ResultSet rs = stmt.executeQuery(query);
            if (rs.next()) {
                String n1 = rs.getString("eid");
                String n2 = rs.getString("name");
                String n3 = rs.getString("password");
                String n4 = rs.getString("sex");
                String n5 = rs.getString("dob");
                String n6 = rs.getString("bloodgroup");
                String n7 = rs.getString("fathername");
                String n8 = rs.getString("qualification");
                String n9 = rs.getString("mailid");
                String n10 = rs.getString("contactnum");
                String n11 = rs.getString("skills");
                String n12 = rs.getString("temporaryadd");
                String n13 = rs.getString("permanentadd");
                String n14 = rs.getString("access_type");
                //  sImage = rs.getBinaryStream("image");
                session.setAttribute("eid", n1);
                session.setAttribute("name", n2);
                session.setAttribute("password", n3);
                session.setAttribute("sex", n4);
                session.setAttribute("dob", n5);
                session.setAttribute("bloodgroup", n6);
                session.setAttribute("fathername", n7);
                session.setAttribute("qualification", n8);
                session.setAttribute("mailid", n9);
                session.setAttribute("contactnum", n10);
                session.setAttribute("skills", n11);
                session.setAttribute("temporaryadd", n12);
                session.setAttribute("permanentadd", n13);
                session.setAttribute("access_type", n14);
                //session.setAttribute("image",sImage);
                response.sendRedirect("EmployeeDetail.jsp");
            } else {
                String message = "Your are not a registered employee.";
                request.setAttribute("message", message);
                request.getRequestDispatcher("index.jsp").forward(request, response);
            }
        } catch (Throwable theException) {
            System.out.println(theException);
        }
    }
}
Employeedetail.jsp
<html>
<head>
  <style>
  </style>
</head>
<body>
<table align=center cellspacing=1 cellpadding=3>
  <tr><Td> Employee name</td><Td><%=name%></td></tr>
  <tr>
  <td><img src="${pageContext.servletContext.contextPath }/retImage?param1=  <%=eid%>">image</td>
    // here i am passing the value and it is passing to servlet also
  </tr>
  <tr><Td>Password</td><Td><%=password%></td></tr>
  <tr><Td>Sex</td><Td><%=sex%></td></tr>
  <tr><Td>dob</td><Td><%=dob%></td></tr>
  <tr><Td>Blodgroup</td><Td><%=bloodgroup%></td></tr>
  <tr><Td>fathername</td><Td><%=fathername%></td></tr>
  <tr><Td>Qualification</td><Td><%=qualification%></td></tr>
  <tr><Td>mail id</td><Td><%=mailid%></td></tr>
  <tr><Td>contact num</td><Td><%=contactnum%></td></tr>
  <tr><Td>skills</td><Td><%=skills%></td></tr>
  <tr><Td>local address</td><Td><%=temporaryadd%></td></tr>
  <tr><Td>permanent Address</td><Td><%=permanentadd%></td></tr>
  <tr><Td>Emp Category</td><Td><%=access_type%></td></tr>
</table><BR>
</div>
</body>
</html>
retImage.java
public class retImage extends HttpServlet
{
    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, java.io.IOException
    {
        HttpSession session = request.getSession(true);
        String sid=(String)session.getAttribute("eid");
        session.setAttribute("sid",sid);
        System.out.println("sid is " +sid);    
        String iid = request.getParameter("param1");
        InputStream sImage;
        try {
            Connection con = ConnectionManager.getConnection();
            String Query= "SELECT image FROM empinfo WHERE eid ='"+iid+"'";
            System.out.println("Query is" +Query);
            Statement stmt = con.createStatement();
            ResultSet rs = stmt.executeQuery(Query);
            System.out.println("..........1");
            if(rs.next())
            {
                System.out.println("........2");
                byte[] bytearray = new byte[1048576];
                int size=0;
                sImage = rs.getBinaryStream(1);    
                response.reset();
                while((size=sImage.read(bytearray))!= -1 ) {
                    response.getOutputStream().write(bytearray,0,size);
                    System.out.println(".......3");
                }
            }
        }
        catch(Exception ex){
            System.out.println("error :"+ex);
        }
    }
}
 
    