Struts 2文件上传拦截器配置问题 [英] Struts 2 File Upload Interceptor configuration problems
问题描述
我在尝试在我的应用程序中配置Struts 2文件上载拦截器时遇到两个问题。我想改变参数 maximumSize
(默认值是2 MB,我需要它是5 MB)和消息资源 struts.messages。 error.file.too.large
(应用程序区域设置为pt_BR,因此邮件是葡萄牙语的,而不是英语)。
配置如下:
struts.properties
struts.locale = pt_BR
struts.custom.i18n.resources = MessageResources
strong> struts.xml
< package name =defaultnamespace =/extends =struts -default>
< interceptors>
< interceptor name =loginclass =br.com.probank.interceptor.LoginInterceptor/>
< interceptor-stack name =defaultLoginStack>
< interceptor-ref name =login/>
< interceptor-ref name =defaultStack/>
< / interceptor-stack>
< / interceptors>
< default-interceptor-ref name =defaultLoginStack/>
...
< / package>
...
< package name =propostanamespace =/ propostaextends =default>
< action name =salvarAnexoPropostamethod =salvarAnexoPropostaclass =br.com.probank.action.AnexoPropostaAction>
< interceptor-ref name =defaultLoginStack>
< param name =fileUpload.maximumSize> 5242880< / param>
< / interceptor-ref>
< result name =success> /jsp/listagemAnexosPropostaForm.jsp< / result>
< result name =input> /jsp/crudAnexoPropostaForm.jsp< / result>
< result name =error> /jsp/error.jsp< / result>
< result name =redirecttype =redirect> $ {redirectLink}< / result>
< / action>
< / package>
MessageResources.properties
...
struts.messages.error.file.too.large = O tamanho do arquivo ...
我的Action实现和我的JSP代码没有什么特别的。他们遵循 http://struts.apache.org中找到的示例/2.1.6/docs/file-upload-interceptor.html 。当我尝试上传超过5 MB的文件时,应用程序显示消息请求被拒绝,因为其大小(6229458)超过配置的最大值(2097152) - 默认的文件上传消息与默认maximumSize值。 p>
我试图将消息资源 struts.messages.error.file.too.large
放在struts消息中。属性,但消息后没有改变。什么是配置文件上载拦截器的正确方法?我使用Struts 2 2.1.7。先感谢。
最后解决了整个谜题! struts.xml
和 MessageResource.properties
已正确配置。问题是 struts.multipart.maxSize
value 。此值必须大于所需的上传限制(我的应用程序中为5242880),因此我将其设置为10000000.如果 struts.multipart.maxSize
值等于或小于 fileUpload.maximumSize
Struts 2用于上传的库在文件上载拦截器有机会完成其任务之前停止上传过程(并写入错误消息)。
I'm having two problems when trying to configure the Struts 2 File Upload Interceptor in my application. I want to change the parameter maximumSize
(the default value is 2 MB, I need it to be 5 MB) and the message resource struts.messages.error.file.too.large
(the app locale is pt_BR, so the message is in portuguese, not english).
The app current configuration follows:
struts.properties
struts.locale=pt_BR
struts.custom.i18n.resources=MessageResources
struts.xml
<package name="default" namespace="/" extends="struts-default">
<interceptors>
<interceptor name="login" class="br.com.probank.interceptor.LoginInterceptor"/>
<interceptor-stack name="defaultLoginStack">
<interceptor-ref name="login" />
<interceptor-ref name="defaultStack"/>
</interceptor-stack>
</interceptors>
<default-interceptor-ref name="defaultLoginStack" />
...
</package>
...
<package name="proposta" namespace="/proposta" extends="default">
<action name="salvarAnexoProposta" method="salvarAnexoProposta" class="br.com.probank.action.AnexoPropostaAction">
<interceptor-ref name="defaultLoginStack">
<param name="fileUpload.maximumSize">5242880</param>
</interceptor-ref>
<result name="success">/jsp/listagemAnexosPropostaForm.jsp</result>
<result name="input">/jsp/crudAnexoPropostaForm.jsp</result>
<result name="error">/jsp/error.jsp</result>
<result name="redirect" type="redirect">${redirectLink}</result>
</action>
</package>
MessageResources.properties
...
struts.messages.error.file.too.large=O tamanho do arquivo...
There is nothing special about my Action implementation and my JSP code. They follow the example found http://struts.apache.org/2.1.6/docs/file-upload-interceptor.html. When I try to upload a file with more than 5 MB the app shows the message "the request was rejected because its size (6229458) exceeds the configured maximum (2097152)" - the default File Upload message with the default maximumSize value.
I try to put the message resource struts.messages.error.file.too.large
in a struts-messages.properties but the message didn't change after that. What is the proper way to configure the File Upload Interceptor? I'm using Struts 2 2.1.7. Thanks in advance.
Finally solved the entire puzzle! struts.xml
and MessageResource.properties
were correctly configured. The problem was struts.multipart.maxSize
value. This value have to be bigger than the desired upload limit (5242880 in my app), so I set it as 10000000. If struts.multipart.maxSize
value is equal or less then fileUpload.maximumSize
the library used by Struts 2 to do the upload stops the upload process (and writes the error message) before the file upload interceptor has a chance to do its job.
这篇关于Struts 2文件上传拦截器配置问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!