Struts中the request was rejected because its size (***) exceeds the configured maximum (2097152)
出现错误的原因:
因为在利用struts中在上传文件的时候,struts的jar包(commons-fileupload)中默认了文件上传的最大值是2097152.所以当你传的文件大小大于这个值的时候就出现了这个错误!
解决办法!
1,我们可以在action中直接重写ActionSupport的addActionError()方法
1.public void addActionError(String anErrorMessage) {
2.
3.//这里要先判断一下,是我们要替换的错误,才处理
4.
5. if (anErrorMessage.startsWith("the request was rejected because its size")) {
6.
7. Matcher m = Pattern.compile("//d+").matcher(anErrorMessage);
8.
9. String s1 = "";
10.
11. if (m.find()) s1 = m.group();
12.
13. String s2 = "";
14.
15. if (m.find()) s2 = m.group();
16.
17. //偷梁换柱,将信息替换掉
18. super.addActionError("你上传的文件大小(" + s1 + ")超过允许的大小(" + s2 + ")");
19. //也可以改为在Field级别的错误
20. // super.addFieldError("file","你上传的文件大小(" + s1 + ")超过允许的大小(" + s2 + ")");
21.
22. } else {//否则按原来的方法处理
23.
24. super.addActionError(anErrorMessage);
25.}
这样上传不会出现异常,但是还是没有上传成功!
2.修改上传的最大上限
<interceptor-ref name="fileUpload">
<param name="maximumSize">1000000</param>
</interceptor-ref>
和上面的方法不一样的是:这个方法不是去除异常,而是在你自己设定的范围内不会出现异常!
最新解决方案是在struts.xml中设置
<constant name="struts.multipart.maxSize" value="100000000"/>
或者sturts的核心包中找到
default.properties中我们可以看到如下片段:
struts.multipart.maxSize=2097152
修改这个大小。
分享到:
相关推荐
the request was rejected because its size (16272982) exceeds the configured maximum (9000000) 2.fileUpload拦截器的maximumSize属性必须小于struts.multipart.maxSize的值。 struts.multipart.maxSize默认2M...
Git-2.37.1,windows64位用。好用的版本。
if (anErrorMessage.startsWith("the request was rejected because its size")) { Matcher m = Pattern.compile("\\d+").matcher(anErrorMessage); String s1 = ""; if (m.find()) { s1 = m.group(); } ...
org.apache.tomcat.util.http.fileupload.FileUploadBase$SizeLimitExceededException:the request was rejected because its size (66704562) exceeds the configured maximum (52428800) ``` 此问题的发生是由于...
- **4.2.8** `UpnpStateVarRequest`: Represents the request for the current value of a state variable in a service state table. - **4.2.9** `UpnpStateVarComplete`: Represents the reply for the current ...
在使用IntelliJ IDEA(简称Idea)上传代码到GitHub时,可能会遇到“Push rejected: Push to origin/master was rejected”的错误。这个问题通常发生在你尝试将一个新的项目推送到一个已存在文件的GitHub仓库时。以下...
- 正确答案:She was crying then, for she was **cast down** by what the teacher said.(cast前加was) - 正确答案:Peter was keen to show **off** his new car when he met his friends.(out→off) - ...
- **例句**: *The court rejected their appeal.* (法院驳回了他们的上诉。) 44. **appreciate** (vt.) 重视,赏识,欣赏 - **例句**: *I appreciate your help very much.* (我非常感谢你的帮助。) 45. **...
version of Delphi and C++ Builder has its own package; DragDropD6.dpk for Delphi 6, DragDropD5.dpk for Delphi 5, DragDropC5.bpk for C++ Builder 5, etc. 4) Add the Drag and Drop Component Suite ...
- "My luggage was rejected by security." - "What should I do with my prohibited items?" ### Unit 8: We Cannot Find Our Reserved Car - **情景**: 找不到预订的车辆。 - **常用表达**: - "We cannot find...
- 英文译文:It is very likely that he will be rejected by the army because of his bad eyesight. - **知识点解析**: - **词汇**: “视力不好”译为“bad eyesight”,“拒绝”用“rejected”表达。 - **...
Because some committers work on different parts, the total number in the committers section of the triangle is higher than in the above triangle. The kernel is the main building block of FreeBSD. ...
3. **Accepted-in development(已接受-开发中)**:需求已被安排在下一个基线中,包括测试阶段。 4. **Released(已发布)**:需求已在当前产品版本中得到满足。 5. **Rejected(已拒绝)**:需求不适用于产品,...
- "Neither the teacher nor the students is content with the result."中的"students"是复数,所以谓语动词"be"也应改为复数形式"are"。 - "Only when she gained admission to the college she come to life....
11. It is very likely that he will be rejected by the army because of his bad eyesight. - **翻译要点:**“It is very likely that…”表示很可能……,“be rejected by”表示被……拒绝。 12. The ...
It emphasizes that money available at the present time is worth more than the same amount in the future due to its potential earning capacity. - **Writing a Financial Calculator in Python**: Step-by-...
The training was fantastic, and all the concepts that were swirling around in their minds prior to the trip suddenly became very real. However, they were the only two ...