扩展文件上传
设置文件上传格式、大小、及提示信息
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文件。