struts 2文件上传没有这样的方法异常

时间:2013-04-01 03:18:39

标签: java java-ee file-upload struts2 nosuchmethoderror

我正在尝试使用struts2上传文件,但没有成功。我一直在关注struts 2展示指南,并经历了这么多论坛。

这是我的JSP

<form action="uploadFile" method="post" enctype="multiform/form-data">
        <div class="overlay">
            <div class="modal">
                <div class="content">
                    <div class="headerText">Upload File</div>

                    <div class="fileuploadwindow">
                         <s:file id="upload" name="upload" label="File"/>
                    </div>

                    <div class="footerText" align="right">


                        <input type="button" class="aButton" value="Close"
                            onclick="closeCreate()"> <s:submit
                            class="aButton" value="Upload"/>
                    </div>
                </div>
            </div>
        </div>
    </form>

这是我的Action类

private File upload;

private String uploadFileName;

private String uploadContentType;

@Override
public String execute() throws Exception {
    LOGGER.error("uploaded file : "+upload);
    LOGGER.error("File name : "+uploadFileName);
    LOGGER.error("content type : "+uploadContentType);
    return super.execute();
}

@Override
public String input() throws Exception {
    // TODO Auto-generated method stub
    return super.input();
}

public String upload() throws Exception {
    return SUCCESS;
}

public File getUpload() {
    return upload;
}

public void setUpload(File upload) {
    this.upload = upload;
}

public String getUploadFileName() {
    return uploadFileName;
}

public void setUploadFileName(String uploadFileName) {
    this.uploadFileName = uploadFileName;
}

public String getUploadContentType() {
    return uploadContentType;
}

public void setUploadContentType(String uploadContentType) {
    this.uploadContentType = uploadContentType;
}

当我尝试上传文件时,我得到例外

Error setting expression 'upload' with value '[Ljava.lang.String;@66fc92f'ognl.MethodFailedException: Method "setUpload" failed for object org.verientouch.opendrive.actions.UploadFileAction@61a8a328 [java.lang.NoSuchMethodException: org.verientouch.opendrive.actions.UploadFileAction.setUpload([Ljava.lang.String;)]

我也经历了Struts 2 file upload Null pointer exceptionstruts2-cant-upload-file-invalid-field-value。但仍然没有成功

请说明我哪里出错了

1 个答案:

答案 0 :(得分:4)

在JSP中你应该使用

<form action="uploadFile" method="post" enctype="multipart/form-data">

因为编码类型错误。