Question

I'm trying to upload the file using struts2 but with no success. I've been following the struts 2 showcase guide and have gone through so many forums.

Here is my 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>

Here is my Action class

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

When I try to upload the file I get exception as

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;)]

I have also gone through Struts 2 file upload Null pointer exception and struts2-cant-upload-file-invalid-field-value. but still no success

Please suggest where am I going wrong

Was it helpful?

Solution

In the JSP you should use

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

because you have wrong encoding type.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top