Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

download pop-up windows error

 
Suka Hati
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 250
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic