File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes download pop-up windows error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "download pop-up windows error" Watch "download pop-up windows error" New topic

download pop-up windows error

Suka Hati
Ranch Hand

Joined: Oct 28, 2004
Posts: 56
i have a method that i call in my servlet for download function. the pop-up window did open but when i try to open it or save it....i cannot click the OK button...the coding is as below...

public void download(HttpServletRequest req, HttpServletResponse resp)throws IOException {
PrintWriter out=resp.getWriter();

String filePath;
//String filePath="C:\\Program Files\\Apache Group\\jakarta-tomcat-4.1.29\\bin\\temp.wav";
String fileNameNew="temp.wav";

resp.addHeader("Content-Disposition", "attachment; filename="+fileNameNew);
File uFile= new File(fileNameNew);
int fSize=(int)uFile.length();
FileInputStream fis = new FileInputStream(uFile);
PrintWriter pw = resp.getWriter();
int c=-1;
// Loop to read and write bytes.

while ((c = != -1){
// Close output and input resources.
}catch(Exception e){
sawan parihar
Ranch Hand

Joined: Aug 24, 2004
Posts: 250
Hi ,
You are using PrintWriter that is used to send character data to the client.

You need to user ServletOutputStream to send binary data.

OutputStream out = res.getOutputStream();


Sawan<br />SCJP,SCWCD,SCBCD<br /> <br />Every exit is an entry somewhere.
I agree. Here's the link:
subject: download pop-up windows error
It's not a secret anymore!