文件上传(四)

扩展文件上传

设置文件上传格式、大小、及提示信息

1.设置文件上传格式和大小都是在struts.xml中配置,使用struts拦截器fileUpload,但要注意一定要把默认拦截器加上,否则找不到fileUpload。

<action name="upload" class="com.test.action.UploadAction">
      <result name="success">/upload/uploadresult.jsp</result>
      <result name="input">/upload/upload.jsp</result>
      
      <!-- 新增拦截器,指定每个上传文件的最大值 -->     
      <interceptor-ref name="fileUpload">
      
       <!--指定上传文件大小-->
       <param name="maximumSize">409600</param>
       
       <!--指定上传文件类型-->
       <param name="allowedTypes">application/vnd.ms-powerpoint</param>
      </interceptor-ref>
      
      <interceptor-ref name="defaultStack"></interceptor-ref>
     </action>

 

2.设置上传文件时的提示信息,是根据struts核心包下的strust-messages.properties文件,可自定义一全局配置文件,重新设置其中的属性。

如在src下新建message.properties全局文件,需在struts.xml中配置<constant name="struts.custom.i18n.resources" value="message"/>

 

如设置文件太大的提示信息,需改变属性struts.messages.error.file.too.large,具体可查看strust-messages.properties文件。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值