Core code:
* * Generated by myeclipse Struts * Template PATH:TEMPLATES/JAVA/JAVACLASS.VTL * * Package com.ljg.struts.action;
Import Java.io.FileOutputStream;
Import Java.io.InputStream;
Import Java.io.OutputStream;
Import Javax.servlet.http.HttpServletRequest;
Import Javax.servlet.http.HttpServletResponse;
Import org.apache.struts.action.Action;
Import Org.apache.struts.action.ActionForm;
Import Org.apache.struts.action.ActionForward;
Import org.apache.struts.action.ActionMapping;
Import Org.apache.struts.upload.FormFile;
Import Com.ljg.struts.form.UserForm; public class Registeraction extends Action {public Actionforward execute (actionmapping mapping, actionform form, H Ttpservletrequest request, HttpServletResponse response) {UserForm UserForm = (UserForm) form;//TODO auto-generated
Method stub String username=userform.getusername ();
Formfile Formfile=userform.getmyphoto ();
String Filename=formfile.getfilename ();
int filesize=formfile.getfilesize (); System.out. println (filename+ "" +filesize);
InputStream Is=null;
OutputStream Os=null;
try {is=formfile.getinputstream ();
String Keepfilepath=this.getservlet (). Getservletcontext (). Getrealpath ("/file");
System.out.println ("keepfilepath====" +keepfilepath);
Os=new fileoutputstream (keepfilepath+ "\" +filename);
int length=0;
Byte[] Bytes=new byte[1024];
while ((Length=is.read (bytes)) >0) {os.write (bytes, 0, length);
} catch (Exception e) {//Todo:handle Exception e.printstacktrace ();
Finally {try {is.close ();
Os.close ();
catch (Exception E2) {//Todo:handle Exception e2.printstacktrace ();
} return null; }
}