日期:2014-05-19  浏览次数:20718 次

struts关于文件上传,总是出错,哪位大哥帮忙看看??
这是action代码:
Java code

package com.itcast.action;

import java.io.File;
import java.io.IOException;

import org.apache.commons.io.FileUtils;
import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class FileUpLoadAction extends ActionSupport{

    private File image;
    private String imageFileName;
    
    
    @Override
    public String execute() throws Exception {
        String realPath =  ServletActionContext.getRequest().getRealPath("/images");
        System.out.println(realPath);
        File savefile=new File(new File(realPath),imageFileName);//
        if(!savefile.exists()){
            savefile.getParentFile().mkdir();//如果文件夹不存在,在创建一个文件夹
        }
        
        FileUtils.copyFile(image, savefile);
        return "success";
    }


    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;
    }
    
    
}





这是错误信息“

Java code

警告: Error setting expression 'image' with value '[Ljava.lang.String;@1e09c92'
ognl.MethodFailedException: Method "setImage" failed for object com.itcast.action.FileUpLoadAction@1e7d730 [java.lang.NoSuchMethodException: com.itcast.action.FileUpLoadAction.setImage([Ljava.lang.String;)]
    at ognl.OgnlRuntime.callAppropriateMethod(OgnlRuntime.java:1292)
    at ognl.OgnlRuntime.setMethodValue(OgnlRuntime.java:1481)
    at ognl.ObjectPropertyAccessor.setPossibleProperty(ObjectPropertyAccessor.java:85)
    at ognl.ObjectPropertyAccessor.setProperty(ObjectPropertyAccessor.java:162)
    at com.opensymphony.xwork2.ognl.accessor.ObjectAccessor.setProperty(ObjectAccessor.java:27)
    at ognl.OgnlRuntime.setProperty(OgnlRuntime.java:2318)
    at com.opensymphony.xwork2.ognl.accessor.CompoundRootAccessor.setProperty(CompoundRootAccessor.java:77)
    at ognl.OgnlRuntime.setProperty(OgnlRuntime.java:2318)
    at ognl.ASTProperty.setValueBody(ASTProperty.java:127)
    at ognl.SimpleNode.evaluateSetValueBody(SimpleNode.java:220)
    at ognl.SimpleNode.setValue(SimpleNode.java:301)
    at ognl.Ognl.setValue(Ognl.java:737)
    at com.opensymphony.xwork2.ognl.OgnlUtil.setValue(OgnlUtil.java:217)
    at com.opensymphony.xwork2.ognl.OgnlValueStack.trySetValue(OgnlValueStack.java:186)
    at com.opensymphony.xwork2.ognl.OgnlValueStack.setValue(OgnlValueStack.java:173)
    at com.opensymphony.xwork2.ognl.OgnlValueStack.setParameter(OgnlValueStack.java:151)
    at com.opensymphony.xwork2.interceptor.ParametersInterceptor.setParameters(ParametersInterceptor.java:292)
    at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:203)
    at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:211)
    at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
    at com.opensymphony.xwork2.DefaultActionInvocat