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

标签 java jakarta-ee file-upload struts2 nosuchmethoderror

我正在尝试使用 struts2 上传文件,但没有成功。我一直在关注 struts 2 showcase guide 并浏览了很多论坛。

这是我的 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 .但还是没有成功

请指出我哪里出错了

最佳答案

在 JSP 中你应该使用

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

因为你的编码类型错误。

关于java - struts 2文件上传没有这样的方法异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15737191/

相关文章:

java - 哪一个将首先被调用? doHeader 或 doView

java - CompletableFuture 与 flatMap 的等价物是什么?

java - 选择 Apache Tomcat 服务器导致 Java EE 下拉菜单失败,NetBeans 7.4

java - 获取 webapp 上下文的 URL(基本 URL)

html - 文件上传在 Windows 10 edge 浏览器中不起作用

ruby-on-rails - 在 Ruby on Rails 3 上上传多个文件

java - Spring中如何使用通配符指定回滚?

java - 多线程不平衡Java

java - 有偏随机数生成器 - Java

javascript - 当我尝试上传中等分辨率图像时,上传多张图像不起作用