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