// Download
Public class downloadaction extends actionsupport {
Private Final Static string downloadfilepath = "/upload /";
Private string filename;
Public String getfilename (){
Return filename;
}
Public void setfilename (string filename ){
This. filename = filename;
}
Public inputstream getinputstream (){
Inputstream in;
In = servletactioncontext. getservletcontext (). getresourceasstream (downloadfilepath + filename );
System. Out. println (downloadfilepath + filename );
System. Out. println (in );
Return in;
}
Public String getdownloadchinesefilename (){
String downloadchinesefilename = filename;
Try {
Downloadchinesefilename = new string (downloadchinesefilename. getbytes (), "ISO8859-1 ");
System. Out. println (downloadchinesefilename );
} Catch (unsupportedencodingexception e ){
E. printstacktrace ();
}
System. Out. println (downloadchinesefilename );
Return downloadchinesefilename;
}
@ Override
Public String execute (){
// Todo auto-generated method stub
Return success;
}
}
// Upload
Public class uploadaction extends actionsupport {
Private Final Static string uploaddir = "/upload ";
Private list <File> file;
Private list <string> filefilename;
Private list <string> filecontentype;
Public list <File> GetFile (){
Return file;
}
Public void setfile (list <File> file ){
This. File = file;
}
Public list <string> getfilefilename (){
Return filefilename;
}
Public void setfilefilename (list <string> filefilename ){
This. filefilename = filefilename;
}
Public list <string> getfilecontentype (){
Return filecontentype;
}
Public void setfilecontentype (list <string> filecontentype ){
This. filecontentype = filecontentype;
}
@ Override
Public String execute () throws exception {
// Todo auto-generated method stub
For (INT I = 0; I <file. Size (); I ++ ){
Uploadfile (I );
}
Return "success ";
}
Private void uploadfile (int I) throws filenotfoundexception, ioexception {
Try {
Inputstream in = new fileinputstream (file. Get (I ));
String dir = servletactioncontext. getrequest (). getrealpath (uploaddir );
System. Out. println (DIR );
File uploadfile = new file (Dir, this. getfilefilename (). Get (I ));
Outputstream out = new fileoutputstream (uploadfile );
Byte [] buffer = new byte [104*1024];
Int length;
While (length = in. Read (buffer)> 0 ){
Out. Write (buffer, 0, length );
}
} Catch (filenotfoundexception e ){
E. printstacktrace ();
} Catch (ioexception e ){
E. printstacktrace ();
}
}
}