JSP页面:
<%@page language="java">
<%@taglib
uri="/WEB-INF/struts-html.tld"
prefix="html">
<html:form action="uploadAction.do" enctype="multipart/form-data">
Please Input Text: <html:text property="myText">
Please Input The File You Wish to Upload: <html:file property="myFile">
<html:submit />
</html:form>
ActionForm bean:
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.upload.FormFile;
public class UploadForm extends ActionForm {
protected String myText;
protected FormFile myFile;
public void setMyText(String text) {
myText = text;
}
public String getMyText() {
return myText;
}
public void setMyFile(FormFile file) {
myFile = file;
}
public FormFile getMyFile() {
return myFile;
}
}
<p>
|
Look at the Javadocs for FormFile to see the methods it exposes to manipulate files in file uploading. Also look at the Javadocs for ActionServlet and ActionMapping for the various parameters you can specify to change how files are uploaded.
Basically in your execute method in your action class you would call ((UploadForm) form).getMyFile() to retrieve the FormFile and do what you want with it.
http://jakarta.apache.org/struts/api/org/apache/struts/upload/FormFile.html