更改struts 2上的上传文件的默认错误消息 [英] Change default error message for upload files on struts 2

查看:237
本文介绍了更改struts 2上的上传文件的默认错误消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在那里,

我有一个多部分表单上传文件,在 struts.xml 更改最大尺寸:

I have a multipart form that upload file and in struts.xml I was able to change the max size:

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

但是当请求大于允许值时,我无法更改默认错误消息。

but I can't change the default error message when the request is bigger than allowed.

我试过添加 struts.messages.error.file.too.large =太大了!但我总是得到相同的讯息:

I've tried add struts.messages.error.file.too.large=Too Large! but I am always getting the same message:


请求被拒绝,因为其大小(31720350)超过配置的最大值(10485760)

the request was rejected because its size (31720350) exceeds the configured maximum (10485760)


推荐答案

该消息来自commons-fileupload框架,它是Struts2框架的文件上传功能的默认实现。 Struts2还使用 JakartaMultipartRequest 解析请求。即使你可以通过配置更改这个类,你不应该这样做。在第一个看来,似乎处理所有由底层框架抛出的异常。例如,您可以更改键的值

The message is coming from commons-fileupload framework which is default implementation of file uploading feature of the Struts2 framework. Struts2 also uses JakartaMultipartRequest to parse request. Even if you can change this class via configuration, you shouldn't do that. At the first look it seems to handle all exceptions thrown by underlying framework. For example you can change the value of the key

struts.messages.upload.error.SizeLimitExceededException=your message   

这篇关于更改struts 2上的上传文件的默认错误消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆