Question

I have set in struts2 the property "struts.multipart.maxSize=524288000" so I can limit the overall upload size to that size. When I upload 2 files that exceed that limit, an exception occurs from the FileUpload interceptor

org.apache.commons.fileupload.FileUploadBase$SizeLimitExceededException: the request was rejected because its size (718551153) exceeds the configured maximum (524288000)

But the code does not reach the action with error so that I can return ERROR from the action and go to my custom error page and show the appropriate message. Instead it goes directly to application error and does not go to the action's method.

Any suggestions on how to return "ERROR" so I can get the proper redirection?

Was it helpful?

Solution

You need to configure input result for your action.

You could also configure fileUpload interceptor with maximumSize parameter for your action:

<action name="..." class="...">
  <interceptor-ref name="defaultStack">
    <param name="fileUpload.maximumSize">524288000</param>
  </interceptor-ref>

  <result name="input">error_page</result>
  <result>success_page</result>
</action>

Then you can override the text of error message by using this key:

struts.messages.error.file.too.large 

OTHER TIPS

For the 'input' result to work correctly you have to have the Validation (org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor) and DefaultWorkflowInterceptors (com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor) as part of your interceptor stack.

Also you can define a custom result name to be used instead of 'input' like below

@InputConfig(resultName = "customInputResultNameWhenValidationFails")
public final String execute() throws Exception {
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top