strut2 自定义文件上传错误信息
2014-04-26 13:01
253 查看
在文件上传过程中我们可以指定拦截器对文件类型、后缀名、大小进行设定,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
<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
相关文章推荐
- SSH框架Struts文件上传自定义错误提示信息解决方案
- strut2 自己定义文件上传错误信息
- struts2文件上传时错误信息
- struts 2.3.8中可能导致上传文件时获取不到文件信息的错误原因
- 2011级-csdn-java-张侃—struts2文件上传错误信息国际化的处理(案例)
- 解决文件无法上传的问题,错误信息:System.IO.DirectoryNotFoundException: Could not find a part of the path.
- 黄聪:wordpress前台自定义用户,调用wp_editor上传附件提示【抱歉,出于安全的考虑,不支持此文件类型】错误。
- springMVC高级部分(数据校验,数据错误回显(自定义格式错误显示),拦截器,异常处理,文件上传,文件下载,springmvc运行流程以及springmvc和struts2对比)
- PHP文件上传($_FILES)错误信息说明
- PHP文件上传、客户端和服务器端加限制、抓取错误信息、完整步骤解析
- jquery 的uploadify上传时出错信息提示成中文!比如文件大小限制提示错误File size:Error
- 使用FLEX进行多文件上传和自定义上传信息
- 【ssh】struts文件上传拦截器(单,多文件上传,以及错误信息的返回)
- 文件上传错误信息说明
- JAVAWEB开发之Struts2详解(三)——Struts2信息国际化、自定义拦截器以及Struts2文件上传和下载详解
- PHP特点之文件上传2——错误信息说明
- C# 采用HttpWebRequest 自定义头信息 上传文件
- struts2文件上传与错误信息国际化
- php 文件上传 错误信息 总结 $_FILES['Filedata']["error"] 值枚举
- struts2文件上传与错误信息国际化