strut2 自定义文件上传错误信息

来源:互联网 发布:pyqt5 for windows 编辑:程序博客网 时间:2024/04/30 10:33

在文件上传过程中我们可以指定拦截器对文件类型、后缀名、大小进行设定,action中的配置:

<interceptor-ref name="fileUpload">
<param name="maximumSize">500000</param>
<param name="allowedTypes">application/vnd.ms-excel</param>
<param name="allowedExtensionsSet">xls</param>
</interceptor-ref>

如果上传文件不符合定义,则会转向input视图上去。在页面上获取错误信息:<s:fielderror></s:fielderror>,注意引入struts标签

如果需要自定义提示信息,可以设置国际化配置信息,在struts.xml文件中添加:

<constant name="struts.custom.i18n.resources" value="message"></constant>

message意思为以message开头的属性配置文件,中文的文件名为:message_zh_CN.properties

message_zh_CN.properties可以自定义错误信息:

struts.messages.error.uploading=\u4E0A\u4F20\u9519\u8BEF
struts.messages.error.file.too.large =\u6587\u4EF6\u592A\u5927
struts.messages.error.content.type.not.allowed =\u8BF7\u9009\u62E9excel\u6587\u4EF6
struts.messages.error.file.extension.not.allowed=\u8BF7\u9009\u62E9.xls\u7ED3\u5C3E\u7684\u6587\u4EF6

0 0
原创粉丝点击