/**
* 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:
/**
* 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: <a href = "$ {CTX}/VA/va! Down. Action "> download </a>