Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

Redirect after close download box

 
Ranch Hand
Posts: 204
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.....

}
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Hi, did you solve this problem? cause I'm having it too...
 
Ranch Hand
Posts: 672
4
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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..
 
    Bookmark Topic Watch Topic
  • New Topic