上传文件时如果超过规定限制,会出现以下错误
在struts2-core-2.5.20.jar\org\apache\struts2\struts-messages.properties中存在文本域大小限制,这里面限制为2mb,可以通过在struts.xml中设置相关参数将此值修改为想要的大小
在struts.xml中配置常量,设置文本域最大的容量限制,这里面设置限制为20mb
<struts>
<constant name="struts.devMode" value="true" />
<!-- 配置文本域文件大小限制 -->
<constant name="struts.multipart.maxSize" value="20971520"></constant>
</struts>
如果超过20mb,则会报错,如果想修改其错误提示信息,则可以从
struts2-core-2.5.20.jar\org\apache\struts2\struts-messages.properties中粘贴以下字段到自己配置的配置文件fileuploadmessage.properties中
struts.messages.upload.error.SizeLimitExceededException=Request exceeded allowed size limit! Max size allowed is: {0} but request was: {1}!
然后稍微对后面的提示信息进行修改,修改成自己想要的提示信息,这里面我稍作修改,注意文件编码要和浏览器显示编码一样,否则会出现中文乱码