CopyCode The Code is as follows :/**
* Implement the file storage function
*
* @ Param text
* File Content
* @ Param filename
* File name
* @ Return
*/
Protected string renderfile (string text, string filename)
Throws ioexception
{
Response. addheader ("content-disposition", "attachment; filename ="
+ Filename );
Response. setcontenttype ("application/octet-stream ");
Response. setcharacterencoding ("gb2312 ");
Response. getwriter (). Write (text );
Response. flushbuffer ();
Response. getwriter (). Close ();
Return NULL;
}
Download action:Copy codeThe Code is as follows :/***//**
* Provides the download method.
* @ Return
*/
Public String down ()
{
String dir = getfullpath () + "/upload/file /";
Try
{
If (! Fileutils. exists (DIR ))
{
New file (DIR). mkdirs ();
}
Random r = new random (system. currenttimemillis ());
Integer randomint = R. nextint ();
This. renderfile ("Test content:" + randomint, randomint + ". txt ");
}
Catch (ioexception E)
{
E. printstacktrace ();
This. rendertext (E. getmessage ());
}
Return NULL;
}
Page Link call: copy Code the code is as follows: download