`
aben328
  • 浏览: 1450815 次
  • 性别: Icon_minigender_1
  • 来自: 广东
社区版块
存档分类

设置Struts2文件上传的类型和大小

阅读更多

设置Struts2文件上传的类型和大小

设置Struts2文件上传的类型和大小:

 在struts.xml中的Action中配置如下:
  
  <!-- 国际化文件 -->
  <constant name="struts.custom.i18n.resources" value="message"></constant>
  
  <action name="upload" class="com.mengya.action.UploadAction">
   <result name="success">/result.jsp</result>
   <!-- 若上传的文件不符合要求则返回input -->
   <result name="input">/index.jsp</result>
   
   <!-- 限制上传的文件的大小,在struts-default.xml中我们可能找到一个fileUpload拦截器 -->
   <interceptor-ref name="fileUpload">
    <!-- 单位为字节,这里为400k 这里的大小是指每个文件上传的大小,若多个文件上传指每一个文件的大小 -->
    <param name="maximumSize">409600</param>
    <!-- 指定文件上传的类型,在X:\Program Files\Apache Software Foundation\Tomcat 6.0\conf\web.xml中Tomcat提定所有文件类型 -->
    <!-- word类型 -->
    <param name="allowedTypes">
     application/msword
    </param>
   </interceptor-ref>
   <!-- 加上默认拦截器 -->
   <interceptor-ref name="defaultStack"></interceptor-ref>
  </action>
  
 在message.properties文件中加上客户化的文件上传提示
 #文件上传类型不允许
 struts.messages.error.content.type.not.allowed = \u4e0a\u4f20\u6587\u4ef6\u7c7b\u578b\u4e0d\u6b63\u786e\uff0c\u8bf7\u91cd\u8bd5\uff01
 #文件上传的大小不允许
 struts.messages.error.file.too.large = \u4e0a\u4f20\u6587\u4ef6\u592a\u5927\uff01
 #这些信息可以在struts2-core-2.1.6.jar下面的struts-message.properties文件里找到

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics