Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help with download servlet

 
Duran Harris
Ranch Hand
Posts: 608
Eclipse IDE Spring Ubuntu
  • Mark post as helpful
  • send pies
  • 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.
 
Poonam Agarwal
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where did you place this servlet class in your deplyoment env.
 
kashif bashir
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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
  • 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
  • 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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic