NullPointerException when uploading a file

倾然丶 夕夏残阳落幕 提交于 2019-11-27 16:23:10

To work properly, the FileUpload Interceptor must run before some other Interceptors in the basicStack;

you can check it out in the struts-default.xml:

Example 1:

<!-- Sample file upload stack -->
<interceptor-stack name="fileUploadStack">
    <interceptor-ref name="fileUpload"/>
    <interceptor-ref name="basicStack"/>
</interceptor-stack>

Example 2:

<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="datetime"/>
    <interceptor-ref name="multiselect"/>
    <interceptor-ref name="staticParams"/>
    <interceptor-ref name="actionMappingParams"/>
    <interceptor-ref name="params">
        <param name="excludeParams">^action:.*,^method:.*</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="deprecation"/>
</interceptor-stack>

Then place it manually before the basicStack declaration, or use a stack (the defaultStack, or the fileUploadStack) and include the Interceptor's name before the parameter's name, for example:

<interceptor-ref name="defaultStack">
    <param name="fileUpload.allowedTypes">image/jpeg,image/gif</param>
</interceptor-ref>

or

<interceptor-ref name="fileUploadStack">
    <param name="fileUpload.allowedTypes">image/jpeg,image/gif</param>
</interceptor-ref>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!