is learning Struts2 and discovering a very important thing. Written here, mainly to remind me and everyone.
That is in the Struts2, as long as it involves the operation of data transmission, you must remember to write the Getter/setter method. It was not a problem, but I did it on his shameless forget!
The following is a code for uploading files.
PackageAction;ImportJava.io.File;Importjava.io.IOException;Importorg.apache.commons.io.FileUtils;ImportOrg.apache.struts2.ServletActionContext;ImportCom.opensymphony.xwork2.ActionSupport; Public classFileupactionextendsActionsupport {PrivateString Fifilename;//file name PrivateString Ficontenttype;//File Type PrivateFile fi;//File Contents PublicString Fileup () {//The first path to the serverString path = Servletactioncontext.getservletcontext (). Getrealpath ("/"); //new A File objectFile File =NewFile (NewFile (path), fifilename); //Copy Picture Try{fileutils.copyfile (fi, file); } Catch(IOException e) {e.printstacktrace (); } return"Pass"; }}
Small problems in the STRUTS2