permaculture playing cards*
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
Author

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 {
//resp.setContentType("text/html");
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";
filePath="/bin/"+fileNameNew;
resp.setContentType("audio/wav");

resp.addHeader("Content-Disposition", "attachment; filename="+fileNameNew);
try{
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.
//pw.print("Test");

while ((c = fis.read()) != -1){
pw.print((char)c);
}
// Close output and input resources.
fis.close();
pw.flush();
pw=null;
//response.sendRedirect("borangtest.jsp");
}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();

Cheers


Sawan<br />SCJP,SCWCD,SCBCD<br /> <br />Every exit is an entry somewhere.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: download pop-up windows error