following is my html file.
<BODY>
<img src="http:\\127.0.0.1:8080\examples\servlet\id2?id=1">
</BODY>
Servlet file:These r the 3 types by which i can send image to front end
1>
String s = request.getParameter("id");
if (s.equals("1")){
String s1 = "http://www.az-maz.com/wall/fantasy/096.jpg";
PrintWriter out = response.getWriter();
out.println("<img src=\"" + s1 + "\">" );
}
2>public void doGet(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException{
String s = request.getParameter("id");
if (s.equals("1")){
sponse.setContentType("image/jpeg");
URL yahoo = new URL("http://www.az-maz.com/wall/fantasy/096.jpg");
BufferedReader in = new BufferedReader(new InputStreamReader(yahoo.openStream()));
PrintWriter out = response.getWriter();
String input;
while((input = in.readLine()) != null){
out.println(input);
}
}
}
Getting the image but not in proper format
3>public void doGet(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException{
String url=new String();
String s = request.getParameter("id");
if (s.equals("1")){
response.setContentType("image/jpeg");
url="http://www.az-maz.com/wall/fantasy/096.jpg";
File f = new File(url);
FileInputStream fin = new FileInputStream(f);
JPEGImageDecoder decoder = JPEGCodec.createJPEGDecoder(fin);
BufferedImage image = decoder.decodeAsBufferedImage();
ServletOutputStream sos = response.getOutputStream();
JPEGImageEncoder encoder =JPEGCodec.createJPEGEncoder(sos);
encoder.encode(image);
}
}
But i am getting just a Small Cross in front end with 1 and 2.
Can anybody plz help me
thanx
<img src