This week's book giveaway is in the HTML/CSS/JavaScript forum.
We're giving away four copies of Practical SVG and have Chris Coyier on-line!
See this thread for details.
Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

downloading image

 
pravallika reddy
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
i am unable to see image after downloading.file is downloading..
i am doing this in jsp.
help me my code is..
user=request.getParameter("user");
filename=request.getParameter("path");
response.setContentType("application/x-filler");
try
{
String downloadFile = "/usr/tomcat/webapps/ap123/users/"+user+"/"+filename;
response.setHeader("Content-Disposition","attachment;filename="+filename);
BufferedInputStream fif = new BufferedInputStream(new FileInputStream(downloadFile));
int data;
int i = 0;
while((data = fif.read()) != -1)
{
out.print((char)data);
// flushBuffer();

}
fif.close();
}
catch(Exception e) { e.printStackTrace(); }
thanks
pravi
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I already told you this in the servlet area!
JSP is designed to send characters. Your code is sending characters where the browser expects binary. Images must be sent in binary, therefore you should be using a servlet to handle image requests.
Didn't you believe me or what???
I just can not understand why people will keep doing this. There is no reason to be afraid of servlets - servlets are your friends.
Bill
 
pravallika reddy
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Bill!!
thanks...i believe u..
then how to include servlet in my jsp file and how to set content type in servlet..
please let me..
thanks in adv
pravi
Originally posted by William Brogden:
I already told you this in the servlet area!
JSP is designed to send characters. Your code is sending characters where the browser expects binary. Images must be sent in binary, therefore you should be using a servlet to handle image requests.
Didn't you believe me or what???
I just can not understand why people will keep doing this. There is no reason to be afraid of servlets - servlets are your friends.
Bill
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your JSP must generate HTML that contains an <IMG tag that points to a servlet. The servlet is not part of the JSP, but is part of the "web application" that the JSP belongs to. Any servlet book (mine included) can show you how to do this.
Here is an example of an image serving servlet - which has some hard-coded file locations.

And here is the JSP page that calls that servlet.

Bill
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!