• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Help with download servlet

 
Ranch Hand
Posts: 608
Eclipse IDE Spring Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

I'm having trouble getting this servlet to run...
when I reguest http://localhost:8080/Duran/download my browser just hangs and say:waiting for localhost..
Please take a look at the servlet and DD for me....



The smiley.jpg is a peer to WEB-INF.
 
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Where did you place this servlet class in your deplyoment env.
 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
try this code.

try {
StringBuffer fileHeader = new StringBuffer();
fileHeader .append("inline");
fileHeader .append("; filename=");
fileHeader .append("file.jpeg");

if(pdfBytes!=null && pdfBytes.length>0) {
response.setHeader("Cache-Control", "max-age=30");
response.setContentType("image/jpeg");
response.setHeader("Content-disposition", fileHeader .toString());
response.setContentLength(imageBytes.length);
response.getOutputStream().write(imageBytes, 0, imageBytes.length);
} else {
response.getOutputStream().print("
No File Found Related Client.");
}

} catch (Exception e) {
e.printStackTrace();
}
 
Duran Harris
Ranch Hand
Posts: 608
Eclipse IDE Spring Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The servlet is in WEB-INF/classes.

Running that code produces:

downloadServlet.java:34: cannot find symbol
symbol : variable pdfBytes
location: class Duran.downloadServlet
 
kashif bashir
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
rename pdfBytes to your imageBytes.
 
Duran Harris
Ranch Hand
Posts: 608
Eclipse IDE Spring Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That code doesn't seem to help..
Am I requesting the right URL for the mapping?:
http://localhost:8080/Duran/download
 
kashif bashir
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you are not assigning bytes rather declaring

byte[] data=new byte[4495];

load bytes from your image resource and assign to data in try catch block.

ommit other code outside try catch.
 
Duran Harris
Ranch Hand
Posts: 608
Eclipse IDE Spring Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No I think I have messed up my tomcat-users file...Even if I request a JSP it just hangs.
Here is tomcat-users:

<?xml version='1.0' encoding='utf-8'?>

What is missing?
 
reply
    Bookmark Topic Watch Topic
  • New Topic