<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <!-- 1配置自定义文件类myRequestParser,继承MultiPartRequest重写 --> <bean type="org.apache.struts2.dispatcher.multipart.MultiPartRequest" name="myRequestParser" class="com.vrv.paw.action.MyJakartaMultiPartRequest" scope="default" optional="true" /> <constant name="struts.multipart.parser" value="myRequestParser" /> <!--struts2 公共配置 --> <constant name="struts.devMode" value="false" /> <constant name="struts.ui.theme" value="simple" /> <constant name="struts.enable.DynamicMethodInvocation" value="true" /> <constant name="struts.objectFactory" value="spring" /> <constant name="struts.action.extension" value=",do" /> <!-- 2文件上传:大小 限制(默认2M,这里限制为10G) --> <constant name="struts.multipart.maxSize" value="10485760000" /> <constant name="struts.multipart.saveDir" value="/temp" /> <!-- 配置struts2的过滤器不拦截授权码的servlet --> <constant name="struts.action.excludePattern" value="/services.*,/servlet/code.*,/scripts/fckeditor/editor/filemanager.*,/Servlet/download.*" /> <!--default config--> <package name="default" namespace="/" extends="struts-default"> <global-results> <result name="downLoadUI" type="chain"> <param name="actionName">downLoadDataAction</param> <param name="namespace">/download</param> </result> <result name="success">/WEB-INF/pages/public/success.jsp</result> <result name="error">/WEB-INF/pages/public/error.jsp</result> <result name="fail">/WEB-INF/pages/public/fail.jsp</result> </global-results> <global-exception-mappings> <exception-mapping result="error" exception="java.lang.Exception" /> </global-exception-mappings> <!--登录退出及主界面配置 --> <action name="welcomeAction_*" class="welcomeAction" method="{1}"> <result name="{1}">/WEB-INF/pages/welcomeAction/{1}.jsp</result> <result name="main">/WEB-INF/pages/welcomeAction/main.jsp</result> <result name="installUI">/WEB-INF/pages/installAction/installUI.jsp</result> <result name="warm">/WEB-INF/pages/code/warm.jsp</result> <result name="overdue">/WEB-INF/pages/code/overdue.jsp</result> <result name="welcome">/WEB-INF/pages/welcomeAction/welcome.jsp</result> </action> </package> <!-- 下载 --> <package name="download" namespace="/download" extends="default"> <action name="downLoadDataAction" class="downLoadDataAction"> <result name="success" type="stream"> <param name="contentType">application/octet-stream;charset=UTF-8</param> <param name="inputName">targetFile</param> <param name="contentDisposition">${browserName}</param> <param name="bufferSize">4096</param> </result> </action> </package> <!--可引入其他的扩展配置文件 --> <include file="struts-extend.xml" /> </struts>
<!-- 2文件上传:大小 限制(默认2M,这里限制为10G) --> <constant name="struts.multipart.maxSize" value="10485760000" />
struts.xml文件中的大小与实际文件大小的关系:1048576(Bytes) = 1024*1024 = 1M实际文件大小.
struts.multipart.maxSize掌控整个项目所上传文件的最大的Size
struts.multipart.maxSize和fileUpload拦截器的maximumSize属性分工不同,总结如下:
1.struts.multipart.maxSize掌控整个项目所上传文件的最大的Size。超过了这个size,后台报错,程序处理不了如此大的文件。fielderror里面会有如下的提示:
the request was rejected because its size (16272982) exceeds the configured maximum (9000000)
2.fileUpload拦截器的maximumSize属性必须小于struts.multipart.maxSize的值。
struts.multipart.maxSize默认2M,当maximumSize大于2M时,必须设置struts.multipart.maxSize的值大于maximumSize。
3.当上传的文件大于struts.multipart.maxSize时,系统报错
当上传的文件在struts.multipart.maxSize和maximumSize之间时,系统提示:
File too large: file "MSF的概念.ppt" "upload__5133e516_129ce85285f__7ffa_00000005.tmp" 6007104
当上传的文件小于maximumSize,上传成功。