This article mainly introduces the example of how to use the showModelDialog pop-up File Download window. The method is very simple. You can directly refer to the following code to use it. When you click "I want to modify", You need to generate an excel file in the background, you must also provide the file download function.
It is easy to generate an excel file and pop-up "File Download:
Click the button to jump to the action. In this action, an Excel file is generated, data is filled, and saved to a Temporary Folder. In the Click Event of the button, an Excel report is generated based on the template, fill in the data, save it to the temporary folder, and then output. wirte (). Everything looks good.
The Action is as follows (the "File Download" window is displayed ):
The Code is as follows:
/**
* @ Paramresponse
* @ ParamdownloadFile
*/
PrivatevoidclientResponse (HttpServletResponseresponse, FiledownloadFile, StringfileName ){
Try {
Response. reset ();
Response. setContentType ("application/octet-stream ");
// The save window is displayed and set to attachment.
Response. setHeader ("Content-Disposition", "attachment; filename =" + newString (fileName. getBytes (), "ISO-8859-1 "));
InputStreaminput = newFileInputStream (downloadFile );
OutputStreamoutput = response. getOutputStream ();
Intc;
// Read the stream and write it to the file
While (c = input. read ())! =-1 ){
Output. write (c );
}
Output. flush ();
Output. close ();
Input. close ();
} Catch (effectione ){
}
}
However, during the test, a new window is always displayed when I click the "I want to modify" button. Baidu: This indicates that the page is opened on the current page.
As follows:
Base: Specifies the default address or default target for all links on the page.
Target: The target page to jump.
This problem has been solved, but the new problem is that files cannot be downloaded. So is there any way I can open or download on this page? Think of the iframe framework. We can set an invisible iframe framework, and then target = iframName can solve the problem.
The Code is as follows:
This Located inBetween