Struts file Upload--a description of the error message configuration problem when the file is too large

Source: Internet
Author: User

Start by adding the following configuration only in the Struts.xml file

<constant name= "struts.multipart.maxSize" value= "10000"/>

Added <s:fielderror/> not shown in index.jsp file

The error message is only printed on the console:

Warning: Request exceeded size limit!
Org.apache.commons.fileupload.fileuploadbase$sizelimitexceededexception:the request was rejected because its size ( 251842) exceeds the configured maximum (10000)

Workaround:

<constant name= "struts.multipart.maxSize" value= "100000000"/>

Add the following configuration to the Interceptor

<interceptor-ref name= "FileUpload" >
<param name= "Allowedtypes" >image/png,image/jpeg</param>
<param name= "MaximumSize" >10000</param> <!--Here The value should be less than the maximum value set in the constant--
</interceptor-ref>
<!--default Interceptor Stack--
<interceptor-ref name= "Defaultstack"/>

The results are as follows:

If you set the value in <param name= "MaximumSize" >10000</param> to a larger size, the file will upload normally.

Description: According to struts source code/org/apache/struts2/struts-messages.properties

The above conclusions can be drawn from this paragraph in the document

struts.messages.bypass.request=bypassing {0}/{1}
Struts.messages.current.file=file {0} {1} {2} {3}
Struts.messages.invalid.file=could not find A, Filename for {0}. Verify a valid file was submitted.
Struts.messages.invalid.content.type=could not find a content-type for {0}. Verify a valid file was submitted.
struts.messages.removing.file=removing file {0} {1}
Struts.messages.error.uploading=error uploading: {0}
Struts.messages.error.file.too.large=file {0} is too large to be uploaded. Maximum allowed size is {4} bytes!
Struts.messages.error.content.type.not.allowed=content-type not allowed: {0} "{1}" "{2}" {3}
Struts.messages.error.file.extension.not.allowed=file extension not allowed: {0} ' {1} ' ' {2} ' {3}

Struts file Upload--a description of the error message configuration problem when the file is too large

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.