UploadAction。javapublic class UploadAction extends ActionSupport {
private File file;
@Override
public String execute() throws Exception {
// TODO Auto-generated method stub
System.out.println(file==null);
return super.execute();
}
public void setFile(File file) {
this.file = file;
} public File getFile() {
return file;
}}
testFileUpload.jsp
<%@ page language="java" contentType="text/html; charset=GB2312"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<html>
<head>
<title></title></head><body> <s:form action="upload" method="POST" >
选择文件:<input type="file" name="upload" size="50" />
<br />
<s:textfield name="file" label="备注" />
<s:submit value="上 传" />
</s:form>
</body>
</html>
struct2.xml
<action name="upload" class="action.UploadAction">
<interceptor-ref name="fileUpload"></interceptor-ref>
<interceptor-ref name="defaultStack"></interceptor-ref>
<result>/WEB-INF/scuess.jsp</result>
</action>
无论我咋弄最后都是空
private File file;
@Override
public String execute() throws Exception {
// TODO Auto-generated method stub
System.out.println(file==null);
return super.execute();
}
public void setFile(File file) {
this.file = file;
} public File getFile() {
return file;
}}
testFileUpload.jsp
<%@ page language="java" contentType="text/html; charset=GB2312"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<html>
<head>
<title></title></head><body> <s:form action="upload" method="POST" >
选择文件:<input type="file" name="upload" size="50" />
<br />
<s:textfield name="file" label="备注" />
<s:submit value="上 传" />
</s:form>
</body>
</html>
struct2.xml
<action name="upload" class="action.UploadAction">
<interceptor-ref name="fileUpload"></interceptor-ref>
<interceptor-ref name="defaultStack"></interceptor-ref>
<result>/WEB-INF/scuess.jsp</result>
</action>
无论我咋弄最后都是空
1.在上传页面form中设置enctype="multipart/form-data"
<s:file name="doc" label="员工照片"></s:file>
2.在action中封装
private File doc; //对应上传的文件
private String docFileName; //对应上传的文件名
要get/set
3.注意jsp页面<s:file name的名字与action中封装的上传字段的对应
规则为:private File 页面上传的name;
private String 页面上传的name+FileName;
File upload
然后提供get、set方法。
你的file是文本与<s:textfield name="file" label="备注" />对应。
file 你没给 GET SET 方法。你没封装。当然NULL 楼上+1