NullPointerException when uploading a file

后端 未结 1 575
星月不相逢
星月不相逢 2020-12-04 03:20

When uploading a file, I get the following error:

Struts Problem Report Struts has detected an unhandled exception: Messages: File: java/io/File         


        
相关标签:
1条回答
  • 2020-12-04 03:58

    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>
    
    0 讨论(0)
提交回复
热议问题