hi
i wrote a servlet which takes the name of a image from the client and displays it to client by converting it to byte array.after displaying the image now when i am trying to print some text i m not able to do so.it simply doesnt print the text even after using PrintWriter
.
i am using jboss application server to deploy it.
here is the servlet-Image.java
:
package javaserv.image;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.PrintWriter;
import javax.imageio.ImageIO;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.swing.ImageIcon;
public class Image extends HttpServlet {
private static final long serialVersionUID = 1L;
public Image()
{
super();
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
String imagename = request.getParameter("imagename");
File fileimage = new File("C:/langs/projects/javaserv/"+imagename+".jpg");
byte [] imagearray;
imagearray = new byte[(int)fileimage.length ()];
FileInputStream fis = new FileInputStream (fileimage);
fis.read (imagearray);
response.setContentType("image/jpeg");
response.setContentLength((int)fileimage.length ());
ServletOutputStream out = response.getOutputStream();
int i=0;
while(i<imagearray.length)
{
out.write(imagearray[i]);
++i;
}
out.flush();
out.close();
out = response.getOutputStream();
response.setContentType("text/html");
out.println("<html><body>");
out.println("here is your image");
out.println("<p>");
out.println("</html></body>");
out.close();
}
}
"imagename" is the name of the image entered by client