Struts2中上传文件配置信息
来源:互联网 发布:数据策划师 编辑:程序博客网 时间:2024/05/16 05:21
在struts.xml中配置,使用的是拦截器fileUploadStack
具体的配置如下:
具体的配置如下:
- <constant name="struts.multipart.maxSize" value="1024000"></constant>
- <action name="demo" class="action.file.FileUploadAction">
- <interceptor-ref name="fileUploadStack">
- <param name="maximumSize">1024000</param>
- <param name="fileUpload.allowedTypes">
- image/gif,image/png,image/bmp,image/pjpeg,image/jpg,image/jpeg
- </param>
- </interceptor-ref>
- <result name="success" type="httpheader">
- <param name="status">200</param>
- </result>
- </action>
补充:只需在<action></action>中加入拦截器引用fileUpload或者fileUploadStack
struts2 上传文件时,如果限制了上传的文件类型,当用户上传被限制的类型时,struts默认显示的错误如下:
Content-Type not allowed: file "icudt42.dll" "upload_47e43c5c_1266edfc786__8000_00000002.tmp" application/x-msdownload
(不知道为什么)
2 在src下新建struts.properties写上
struts.messages.error.content.type.not.allowed=文件类型不正确
struts.messages.error.file.too.large=上传的文件太大
struts.messages.error.uploading=上传出错
注释:在properties文件中中文是乱码的,要用native2ascii转一下
- <interceptor-ref name="fileUpload">
- <!-- 配置允许上传的文件类型,多个用","分隔 -->
- <param name="allowedTypes">
- image/bmp,image/png,image/gif,image/jpeg,image/jpg
- ,image/x-png, image/pjpeg<o:p></o:p>
- </param>
- <!-- 配置允许上传的文件大小,单位字节 -->
- <param name="maximumSize">102400</param>
- </interceptor-ref>
struts2 上传文件时,如果限制了上传的文件类型,当用户上传被限制的类型时,struts默认显示的错误如下:
Content-Type not allowed: file "icudt42.dll" "upload_47e43c5c_1266edfc786__8000_00000002.tmp" application/x-msdownload
但这种显示不是很友好,要自定义该错误,需要做的是:
1 在struts.xml中添加<constant name="struts.custom.i18n.resources" value="struts" />(不知道为什么)
2 在src下新建struts.properties写上
struts.messages.error.content.type.not.allowed=文件类型不正确
struts.messages.error.file.too.large=上传的文件太大
struts.messages.error.uploading=上传出错
注释:在properties文件中中文是乱码的,要用native2ascii转一下
阅读全文
0 0
- Struts2中上传文件配置信息
- Ext+struts2 上传文件信息
- Struts2中处理文件上传
- struts2中实现文件上传
- Struts2中实现文件上传
- Struts2中多文件上传
- FCKeditor.java+Struts2的上传文件配置
- Struts2 文件上传拦截器配置问题
- Struts2 文件上传struts.properties配置
- struts2.x 文件上传 文件大小配置问题!
- struts2.x 文件上传 文件大小配置问题!
- struts2实现文件上传(配置拦截器)
- struts2的文件上传(0):struts2的文件上传并且上传目录可动态配置
- 在Struts2中实现文件上传
- 在Struts2中实现文件上传
- 在Struts2中实现文件上传
- 在Struts2中实现文件上传
- Struts2中上传文件相关设置
- PHP spvoice
- K&R《C程序设计语言》p17:求m的n次方
- Ubuntu下slickedit的安装与配置
- MySql 实用配置(1)读写分离与常用配置
- Android Retrofit网络请求Service,@Path、@Query、@QueryMap、@Map...
- Struts2中上传文件配置信息
- 支付宝支付小结
- 9、10
- Spring 定时任务(Schedule) 和线程
- 配置Log4j(很详细)
- 欢迎使用CSDN-markdown编辑器
- 针对接口编程及敏捷编程
- Mybatis源码分析
- python 连接C++库出现的问题解决办法