struts2文件上传,取不到文件
fileload.jsp
<s:form action="upload.action" enctype="multipart/form-data" method="post">
文件标题: <s:text name="titile"></s:text><br/>
选择文件:<s:file name="upload"></s:file>
<s:submit value="提交"> </s:submit>
</s:form>
FiledAction
public class FiledAction extends ActionSupport {
//封装文件标题请求参数的属性
private String titile;
//封装上传文件域的属性
public File upload;
//封装上传文件类型的属性
private String uploadContentType;
//封装上传文件名的属性
private String uploadFileName;
//接收依赖注入的属性
private String savePath;
public String getTitile() {
return titile;
}
public void setTitile(String titile) {
this.titile = titile;
}
public File getUpload() {
return upload;
}
public void setUpload(File upload) {
this.upload = upload;
}
public String getUploadContentType() {
return (this.uploadContentType);
}
public void setUploadContentType(String uploadContentType) {
this.uploadContentType = uploadContentType;
}
public String getSavePath() {
return ServletActionContext.getRequest().getRealPath(savePath);
//return savePath;
}
public void setSavePath(String savePath) {
this.savePath = savePath;
}
public String getUploadFileName() {
return uploadFileName;
}
public String fileupload() throws Exception {
System.out.println(getUpload());
//以服务器的文件保存地址盒原文件名建立上传文件输出流
FileOutputStream fos=new FileOutputStream(getSavePath()+"\\"+getUploadFileName());
//以上文件建一个文件上传流
FileInputStream fis=new FileInputStream(getUploadFileName());
//将上传文件的内容写入服务器
byte[] buffer=new byte[1024];
int len=0;
while((len=fis.read(buffer))>0){
fos.write(buffer, 0, len);
}
return "success";
}
public void setUploadFileName(String uploadFileName) {
this.uploadFileName = uploadFileName;
}
}
struts.xml文件
<action name="upload" class="com.caishuang.action.FiledAction" method="fileupload">
<param name="savePath">/upload</param>
<result name="success">/succ.jsp</result>
</action>
调试运行发现 System.out.println(getUpload()); 打印为null ,getUploadFileName() 也为null
为什么取不到上传的文件呢 ??
希望各位高手能指点迷津