• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

downloading image

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic