文件上传,下载

关于和文件上传的配置,查看webwork.properties文件内容

假设文件域的名字是xxx
在接收文件的action中一个File类型的属性,名字也是xxx,该file存放的是上传框架的零时文件,
一个接收文件名的属性,String,xxxFileName
一个接收文件类型属性,String xxxContextType
另外还有一个savePath属性,该属性通过配置文件来设置。如:
<action name="upload" class="com.UploadAction">
<param name="savePath">/upload</param>
<result>aaaa.jsp</result>
</action>

action中只要把xxx(零时文件读出来)输出到本地磁盘就可以了。

支持的上传文件类型设置
<interceptor name="fileUpload" class="com.opensymphony.webwork.interceptor.FileUploadInterceptor"/>,这个是上传文件的拦截器。默认是调用了这个拦截器的。由于要设置支持的上传类型,所以要改变它的参数,
<action name="upload" class="action.UpLoadAction">
<param name="savePath">/upload</param>
<interceptor-ref name="fileUpload">
<param name="allowedTypes">image/bmp,image/png,image/gif</param>
<param name="maximumSize">2000</param>
</interceptor-ref>
<interceptor-ref name="defaultStack"></interceptor-ref>
<result>t.jsp</result>
</action>
这里引用了fileUpload,所以要手动调用defaultStack栈

设置错误消息:
webwork.messages.error.content.type.not.allowed=\u4f60\u4e0a\u4f20\u7684\u6587\u4ef6\u7c7b\u578b\u9519\u8bef\uff01
webwork.messages.error.file.too.large=\u6587\u4ef6\u592a\u5927
比如我在webwork.properties设置了国际化文件是webwork.custom.i18n.resources=message
那么,我在message对应的资源文件中设置
webwork.messages.error.content.type.not.allowed,用于设置文件类型不支持的错误消息
webwork.messages.error.file.too.large用于文件过大的错误消息
还有一个是用于设置其他错误的
webwork.message.error.uploading

关于详细的错误消息定义可以查看FileUploadInterceptor


下载
结果类型使用stream,action中需要设置一个属性类型是InputStream,
参数
<result name="" type="stream">
<param name="contentType">image/gif</param>
<param name="inputName">image/gif</param>
<param name="contentDisposition">filename="struts.gif"</param>
<param name="contentType">4096</param>
</result>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值