求帮助~~struts 2.3.4 文件上传,FileName,ContentType和File全为NULL
刚开始学Struts2,下午参照黑弓老师的视频写一个简单的文件上传模块,结果弄了一下午,File,FileName和ContentType全为null,实在搞不懂了,大家帮我看看,谢谢了!!
先贴代码:
Fileupload.jsp代码
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title><s:text name="loginPage" /></title>
</head>
<body>
<s:form action="fileUpload" method="post" enctype="multipart/form-data">
选择文件:
<s:file name="upload"></s:file>
<s:submit></s:submit>
</s:form>
</body>
</html>
----------------------------
Uploadaction.java代码
public class UploadAction extends ActionSupport {
private File upload;
private String uploadContentType;
private String uploadFileName;
public File getUpload() {
return upload;
}
public void setUpload(File upload) {
this.upload = upload;
}
public String getUploadContentType() {
return uploadContentType;
}
public void setUploadContentType(String uploadContentType) {
this.uploadContentType = uploadContentType;
}
public String getUploadFileName() {
return uploadFileName;
}
public void setUploadFileName(String uploadFileName) {
this.uploadFileName = uploadFileName;
}
public String execute() throws Exception {
System.out.println(uploadContentType + " : " + uploadFileName + "\n");
FileInputStream fis = new FileInputStream(upload);
FileOutputStream fos = new FileOutputStream("D:/" + uploadFileName);
byte[] buffer = new byte[1024];
int length = 0;
while((length = fis.read(buffer)) != -1) {
fos.write(buffer, 0, length);
}
fis.close();
fos.close();
return null;
}
}
------------------------
Struts.xml代码
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"struts-2.3.dtd">
<struts>
<constant name="struts.devMode" value="true"></constant>
<constant name="struts.configuration.xml.reload" value="