This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
    Bookmark Topic Watch Topic
  • New Topic

Redirect after close download box  RSS feed

 
michael yue
Ranch Hand
Posts: 204
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hi,

I have a situation where in a jsp page, after clicking on a download button it will go to servlet to perform donwload which will prompt out a dialog box to specify which path to save the file. After that I wanted to either redirect back to another jsp page or refresh. But after download dialog box is closed, the servlet can't seem to perform redirect or refresh. Is it have to do with servlet timeout because of the download dialog box halted the process? My code that didn't work is as below. Any other sugestions?

(From main)
res.setHeader("Refresh", "2; URL=/tkflist.jsp");
downloadFile(downloaditem, filenamebak, res);
//res.sendRedirect("tkflist.jsp?status=ok");

(Method)
public void downloadFile(String fileName, String thepath, HttpServletResponse res){
InputStream in = null;
try {
OutputStream out = res.getOutputStream( );

//res.setHeader("Content-Disposition","attachment;filename=ExportFileSpt.txt");
res.setContentType("application/x-download");
res.setHeader("Content-Disposition","attachment; filename=\"" + fileName + "\"");
in = new BufferedInputStream(new FileInputStream(thepath));
byte[ ] buf = new byte[2048];
int bytesRead;
while ((bytesRead = in.read(buf)) != -1) {
out.write(buf, 0, bytesRead);
}
in.close();
out.flush();
out.close();
}catch(Exception ex){}//catch block here and err handling.....

}
 
manuela marginean
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hi, did you solve this problem? cause I'm having it too...
 
Prasad Krishnegowda
Ranch Hand
Posts: 672
4
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Report post to moderator
The thread is 6 years old, so its very unlikely that the OP will be watching this thread. So better you can create a new thread with all the details and the problem you are facing, so that you get useful replies..
 
It is sorta covered in the JavaRanch Style Guide.
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!