my problem is that I have a program which does make a file & stream it out to the user & I have two problem:
1) first how do change the file name & type (x.sql)
2) what if there's an exception while making the file & I want to redirect the user to an error page because my return type of my method is void when we want to write into outputstream in servlet !
my program is like this:
@RequestMapping(value = "/test/{jobid}")
public void dumpData(@PathVariable("jobid") long jobid, HttpServletResponse response) {
try {
response.setContentType("application/octet-stream");
ServletOutputStream out = response.getOutputStream();
String downloadOutput = "";
// AM I ABLE TO SET FILENAME SO THE USER DOWNLOAD THE FILE WITH THAT NAME ?
// DOES SETHEADER HELP ME IN THIS CASE ?
... (making downloadOutput String by values coming from somewhere)
out.write(downloadOutput.getBytes("UTF-8"));
out.flush();
out.close();
} catch(SomeException e){
//WHEN THE RETURN TYPE IS VOID HOW TO REDIRECT USER TO ERROR PAGE IN CASE OF SOME PROBLEM ?
//(INFO:)IF WE DEFINE STRING AS RETURN TYPE THE PROGRAM WILL GET EXCEPTION
}