struts 2.3.8中可能导致上传文件时获取不到文件信息的错误原因

我的博客:www.while0.com

我的博客:www.shishangguan.net

1.第一种是由于给submit按钮提供了name属性,struts在接收表单的时候没找到对应的set和get方法,则会报错。
   解决办法:删除submit的name属性。

2.还有一种就是在接收文件时,set方法和get方法必须与文件属性名称一致,否则就会出错。而在接收其他参数时则不需要如此

 1 package test;
 2 import java.io.*;
 3 public class Uploadtest extends  com.opensymphony.xwork2.ActionSupport {
 4     private File image;
 5     private String imageFileName;
 6     private String imageContentType;
 7     //private int imageSize;
 8     
 9     public void setImage(File image)
10     {
11         this.image=image;
12     }
13     public String getImageFileName()//可以设置成功
14     {
15         return this.imageFileName;
16     }
17     public void setImageFileName(String imageFileName)
18     {
19         this.imageFileName=imageFileName;
20     }
21     
22     public String getType() {//不可以设置成功
23         return imageContentType;
24     }
25     public void setType(String imageContentType) {
26         this.imageContentType = imageContentType;
27     }
28     public String execute()
29     {
30         System.out.println(image.getPath());
31         System.out.println("!!!!!!"+this.imageFileName+"@@@@@@");
32         return "success";
33     }
34 }
原文地址:https://www.cnblogs.com/yamadie/p/2916704.html