struts2出现Error setting expression解决办法

来源:互联网 发布:java if 缩写 编辑:程序博客网 时间:2024/06/13 23:48

我在在使用struts2上传文件时出现Error setting expression ‘afileFileName’ with value [‘jsf.jpg’, ]

一开始百度查到的是,很多人在上传文件时忘记设置form表单的MIME编码,或者不小心写错了,就是下面这句(enctype=”multipart/form-data”)

“`

我的问题不是这个,仔细看了一遍,发现我在action中写接收文件名称的属性时,将xxxFileName写成了
xxxFilename(这里的xxx代表上传文件的file的name),就差了一个n的大小写。。。
本来是照着struts的API文档里写的,这个属性名称是复制的,就怕自己拼写错误,在一开始上传操作时,
无法获取到文件名,后来发现属性名称不对(这时候的n还是小写),然后我就改了,可是这个时候,set和get
方法还是根据以前的属性名称生成的,被我给忽略了,所以就出现了上面的错误
这是实现上传的API:

  //And then in your action code you'll have access to the File object if you provide    setters according to the naming convention documented in the start.  package com.example; import java.io.File; import com.opensymphony.xwork2.ActionSupport;public UploadAction extends ActionSupport {   private File file;   private String contentType;   private String filename;   public void setUpload(File file) {      this.file = file;   }   public void setUploadContentType(String contentType) {      this.contentType = contentType;   }   public void setUploadFileName(String filename) {      this.filename = filename;   }   public String execute() {      //...      return SUCCESS;   }

}

struts2文档中的这个属性不是驼峰命名法。。。,不知道还有哪些地方有这种问题,所以在使用struts2
中的属性时,尽量不要直接去看属性的名称,而是去看它的set和get方法怎么写的
在这里记录一下我的这个错误

1 0
原创粉丝点击