0

上传大文件后,我只在控制台中收到警告消息,但并没有阻止我,消息如下:

WARN FileUploadInterceptor:56 - 要上传的文件太大:_7fa0eae6b3a9b769f938dd52c0fde541_imgThumb "170587_10150170888553504_2474786_o.jpg" "upload__24f6477e_140de8108208__.80000_40080000408

这是我的 Struts.xml 设置:

<constant name="struts.multipart.maxSize" value="20480000" />
...

<package name="Image" extends="json-default,struts-default,my-default">
    ...
    <action name="saveImage" class="example.Test" method="saveImg"> 
        <interceptor-ref name="defaultStack"></interceptor-ref>
        <interceptor-ref name="exception"/>
        <interceptor-ref name="fileUpload">
            <param name="maximumSize">1</param>
            <param name="allowedTypes">image/tiff,image/jpeg</param>
        </interceptor-ref>
        <interceptor-ref name="params" />
        <interceptor-ref name="validation" />
        <interceptor-ref name="json">
            <param name="contentType">application/json</param>
        </interceptor-ref>
        <result name="success" type="json">
            <param name="root">save</param>
        </result>
        <result name="error" type="json">
            <param name="root">save</param>
        </result>
        <result name="invalid.token">/WEB-INF/jsp/invalidToken.jsp</result>
    </action>

任何帮助,将不胜感激!

4

1 回答 1

1

您包含两次文件上传拦截器,因为它已经存在于默认堆栈中。

默认堆栈定义为:

<!-- A complete stack with all the common interceptors in place.
         Generally, this stack should be the one you use, though it
         may do more than you need. Also, the ordering can be
         switched around (ex: if you wish to have your servlet-related
         objects applied before prepare() is called, you'd need to move
         servletConfig interceptor up.

         This stack also excludes from the normal validation and workflow
         the method names input, back, and cancel. These typically are
         associated with requests that should not be validated.
-->

<interceptor-stack name="defaultStack">
    <interceptor-ref name="exception"/>
    <interceptor-ref name="alias"/>
    <interceptor-ref name="servletConfig"/>
    <interceptor-ref name="i18n"/>
    <interceptor-ref name="prepare"/>
    <interceptor-ref name="chain"/>
    <interceptor-ref name="scopedModelDriven"/>
    <interceptor-ref name="modelDriven"/>
    <interceptor-ref name="fileUpload"/>
    <interceptor-ref name="checkbox"/>
    <interceptor-ref name="multiselect"/>
    <interceptor-ref name="staticParams"/>
    <interceptor-ref name="actionMappingParams"/>
    <interceptor-ref name="params">
        <param name="excludeParams">dojo\..*,^struts\..*,^session\..*,^request\..*,^application\..*,^servlet(Request|Response)\..*,parameters\...*</param>
    </interceptor-ref>
    <interceptor-ref name="conversionError"/>
    <interceptor-ref name="validation">
        <param name="excludeMethods">input,back,cancel,browse</param>
    </interceptor-ref>
    <interceptor-ref name="workflow">
        <param name="excludeMethods">input,back,cancel,browse</param>
    </interceptor-ref>
    <interceptor-ref name="debugging"/>
</interceptor-stack>

那么你实际上为你的 Action 定义的是

<action name="saveImage" class="example.Test" method="saveImg">     

    <!-- DEFAULT STACK IMPORT EXPLODED -->
    <interceptor-ref name="exception"/>
    <interceptor-ref name="alias"/>
    <interceptor-ref name="servletConfig"/>
    <interceptor-ref name="i18n"/>
    <interceptor-ref name="prepare"/>
    <interceptor-ref name="chain"/>
    <interceptor-ref name="scopedModelDriven"/>
    <interceptor-ref name="modelDriven"/>
    <interceptor-ref name="fileUpload"/>
    <interceptor-ref name="checkbox"/>
    <interceptor-ref name="multiselect"/>
    <interceptor-ref name="staticParams"/>
    <interceptor-ref name="actionMappingParams"/>
    <interceptor-ref name="params">
        <param name="excludeParams">dojo\..*,^struts\..*,^session\..*,^request\..*,^application\..*,^servlet(Request|Response)\..*,parameters\...*</param>
    </interceptor-ref>
    <interceptor-ref name="conversionError"/>
    <interceptor-ref name="validation">
        <param name="excludeMethods">input,back,cancel,browse</param>
    </interceptor-ref>
    <interceptor-ref name="workflow">
        <param name="excludeMethods">input,back,cancel,browse</param>
    </interceptor-ref>
    <interceptor-ref name="debugging"/>

    <!-- YOUR ADDITIONAL SETTINGS -->
    <interceptor-ref name="exception"/>
    <interceptor-ref name="fileUpload">
        <param name="maximumSize">1</param>
        <param name="allowedTypes">image/tiff,image/jpeg</param>
    </interceptor-ref>
    <interceptor-ref name="params" />
    <interceptor-ref name="validation" />
    <interceptor-ref name="json">
        <param name="contentType">application/json</param>
    </interceptor-ref>
    <result name="success" type="json">
        <param name="root">save</param>
    </result>
    <result name="error" type="json">
        <param name="root">save</param>
    </result>
    <result name="invalid.token">/WEB-INF/jsp/invalidToken.jsp</result>
</action>

如您所见,许多拦截器被定义了两次。只需创建一个自定义拦截器堆栈,并在您需要的所有操作中使用它,或者手动指定拦截器而不包括默认堆栈。

就像是

    <interceptor-ref name="exception"/>
    <interceptor-ref name="alias"/>
    <interceptor-ref name="servletConfig"/>
    <interceptor-ref name="i18n"/>
    <interceptor-ref name="prepare"/>
    <interceptor-ref name="chain"/>
    <interceptor-ref name="scopedModelDriven"/>
    <interceptor-ref name="modelDriven"/>
    <interceptor-ref name="fileUpload">
        <param name="maximumSize">1</param>
        <param name="allowedTypes">image/tiff,image/jpeg</param>
    </interceptor-ref>
    <interceptor-ref name="checkbox"/>
    <interceptor-ref name="multiselect"/>
    <interceptor-ref name="staticParams"/>
    <interceptor-ref name="actionMappingParams"/>
    <interceptor-ref name="params">
        <param name="excludeParams">dojo\..*,^struts\..*,^session\..*,^request\..*,^application\..*,^servlet(Request|Response)\..*,parameters\...*</param>
    </interceptor-ref>
    <interceptor-ref name="conversionError"/>
    <interceptor-ref name="validation">
        <param name="excludeMethods">input,back,cancel,browse</param>
    </interceptor-ref>
    <interceptor-ref name="workflow">
        <param name="excludeMethods">input,back,cancel,browse</param>
    </interceptor-ref>
    <interceptor-ref name="debugging"/>
    <interceptor-ref name="json">
        <param name="contentType">application/json</param>
    </interceptor-ref>
于 2013-09-02T12:25:52.190 回答