struts2上传文件为空 这是怎么回事儿
求大神帮忙啊 获取的文件为空 哪里出了毛病?
JSP表单:
<form action="${pageContext.request.contextPath}/listexecute.action" enctype="multipart/form-data" method="post">
<input type="file" name="image">
<input type="submit" value="上传"/>
</form>
ACTION:
public class HelloWorldAction {
private File image;
private String imageFileName;
public File getImage() {
return image;
}
public void setImage(File image) {
this.image = image;
}
public String getImageFileName() {
return imageFileName;
}
public void setImageFileName(String imageFileName) {
this.imageFileName = imageFileName;
}
public String execute() throws Exception {
String realpath = ServletActionContext.getServletContext().getRealPath("/image");
System.out.println("1");
System.out.println(realpath);
if(image!=null) {
File saveFile = new File(new File(realpath),imageFileName);
if(!saveFile.getParentFile().exists()) {
System.out.println("2");
saveFile.getParentFile().mkdirs();
}
FileUtils.copyFile(image,saveFile);
System.out.println("3");
ActionContext.getContext().put("msg","文件上传成功!");
}
return "success";
}
}
XML配置:
<package name="ln" extends="struts-default">
<action name="list*" class="org.action.HelloWorldAction" method="{1}">
<result name="success">/message.jsp</result>
</action>
</package>
[解决办法]
我记得struts框架action里面用于保存文件的有3个私有成员,你怎么只有两个
[解决办法]
是不是重启删除了,上传路径别放项目里。