Java Spring MVC-上载文件被Spring security阻止

Java Spring MVC-上载文件被Spring security阻止,java,spring,spring-mvc,file-upload,spring-security,Java,Spring,Spring Mvc,File Upload,Spring Security,我正在上传文件。它适合我,但如果我想使用上传文件,它就不起作用。我犯了这个错误 HTTP Status 405 - Request method 'POST' not supported 但如果我在web.xml中对这些行进行注释,它会起作用: <filter> <filter-name>springSecurityFilterChain</filter-name> <filter-class>org.spring

我正在上传文件。它适合我,但如果我想使用上传文件,它就不起作用。我犯了这个错误

HTTP Status 405 - Request method 'POST' not supported
但如果我在web.xml中对这些行进行注释,它会起作用:

<filter>
        <filter-name>springSecurityFilterChain</filter-name>
        <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
    </filter>


    <filter-mapping>
        <filter-name>springSecurityFilterChain</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
JSP


上传文件请求页面
要上载的文件:
名称:

按这里上传文件!
Spring安全配置

<beans:beans xmlns="http://www.springframework.org/schema/security"
    xmlns:beans="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/security
    http://www.springframework.org/schema/security/spring-security-3.2.xsd">

    <!-- enable use-expressions -->
    <http auto-config="true" use-expressions="true">

        <intercept-url pattern="/admin/**" access="hasRole('ROLE_ADMIN')" />

        <!-- access denied page -->
        <access-denied-handler error-page="/403" />

        <form-login 
            login-page="/login" 
            default-target-url="/admin/goods" 
            authentication-failure-url="/login?error" 
            username-parameter="username"
            password-parameter="password" />
        <logout logout-success-url="/login?logout"  />
        <!-- enable csrf protection -->
        <csrf/>
    </http>

    <!-- Select users and user_roles from database -->
    <authentication-manager>
      <authentication-provider>
        <jdbc-user-service data-source-ref="dataSource"
          users-by-username-query=
            "select username,password, enabled from admin where username=?"
          authorities-by-username-query=
            "select username, role from user_roles where username =?  " />
      </authentication-provider>
    </authentication-manager>

</beans:beans>

更改以下内容

<form method="POST" action="uploadOneFile" enctype="multipart/form-data">
<form method="POST" action="/uploadOneFile" enctype="multipart/form-data">

追随

<form method="POST" action="uploadOneFile" enctype="multipart/form-data">
<form method="POST" action="/uploadOneFile" enctype="multipart/form-data">


让我知道这是否有效,如果无效,那么我将建议另一件事。

我解决了这个问题,我在表单操作的末尾添加了?${{u csrf.parameterName}=${u csrf.token}

<form method="POST" action="uploadOneFile?${_csrf.parameterName}=${_csrf.token}" enctype="multipart/form-data">


现在它工作了

您需要向我们展示您的JSP/HTML页面代码,您可以在其中生成用于提交文件的表单。您还需要粘贴控制器代码,以便我们可以看到其processedI如何更新我的问题(添加了JSP、控制器和安全配置)谢谢!我也有同样的问题。我通过@user1604064解决了这个问题。你救了我的命没用。我的应用程序在
http://localhost:8080/spring-hibernate4/
所以当我设置时,我被转发到
http://localhost:8080/uploadOneFile
我试图设置,但得到的错误与HTTP Status 405相同-请求方法“POST”不受支持为什么会有这些星号?只有当我移除它们时,它才对我有效。
<form method="POST" action="uploadOneFile" enctype="multipart/form-data">
<form method="POST" action="/uploadOneFile" enctype="multipart/form-data">
<form method="POST" action="uploadOneFile?${_csrf.parameterName}=${_csrf.token}" enctype="multipart/form-data">