您的位置:首页 > 编程语言 > Java开发

struts2文件上传提示信息国际化

2015-05-25 16:33 309 查看
1、在src的目录下新建文件fileUpload.properties

如图:



fileUpload.properties文件内容为(把英文提示自定义为中文提示)

struts.messages.error.uploading=上传错误: {0}
struts.messages.error.file.too.large=上传文件过大: {0} "{1}" "{2}" {3}
struts.messages.error.content.type.not.allowed=:不支持的文件类型 {0} "{1}"
struts.messages.error.file.extension.not.allowed=不支持的文件扩展名: {0} "{1}" "{2}" {3}


2、在struts.xml中配置文件名

<struts>
<!-- 指定国际化资源文件的baseName为fileUpload-->

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

</struts>


3.在action中应用拦截器

<!-- 通过拦截器来限制上传文件的类型和大小 -->
<interceptor-ref name="fileUpload">
<!-- 文件过滤 -->
<!--  <param name="allowedTypes">application/x-zip-compressed,application/vnd.ms-excel</param>    -->
<!-- 允许后缀名为xls的文件上传   注意:allowedTypes的优先级别高于allowedExtensions,
如果配置了allowedTypes,则allowedExtensions将不起作用  -->
<param name="allowedExtensions">
csv,zip
</param>
<!--  单个文件大小, 以字节为单位  -->
<param name="maximumSize">10240000000</param>
</interceptor-ref>
<!--  默认拦截器必须放在fileUpload之后,否则无效  -->
<interceptor-ref name="defaultStack"></interceptor-ref>


4.jsp文件中便可显示定义的文件提示内容

<s:fielderror> </s:fielderror>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: