File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Help with download servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Help with download servlet" Watch "Help with download servlet" New topic
Author

Help with download servlet

Duran Harris
Ranch Hand

Joined: Nov 09, 2008
Posts: 598

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.


===>SCJP 1.5(72%)<===
==>SCWCD1.5(76%)<===
Poonam Agarwal
Ranch Hand

Joined: May 12, 2008
Posts: 323
Where did you place this servlet class in your deplyoment env.


Thanks <br />Poonam Agarwal SCWCD 86%
kashif bashir
Greenhorn

Joined: May 14, 2008
Posts: 17
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

Joined: Nov 09, 2008
Posts: 598

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

Joined: May 14, 2008
Posts: 17
rename pdfBytes to your imageBytes.
Duran Harris
Ranch Hand

Joined: Nov 09, 2008
Posts: 598

That code doesn't seem to help..
Am I requesting the right URL for the mapping?:
http://localhost:8080/Duran/download
kashif bashir
Greenhorn

Joined: May 14, 2008
Posts: 17
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

Joined: Nov 09, 2008
Posts: 598

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?
 
wood burning stoves
 
subject: Help with download servlet
 
Similar Threads
File download servlet
error in servlet due to reasons unknown
different behavior occurs, why?
problem with this cookie program, getting a blank output
error in downloading file