Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java SpringMVC-HTTP状态405-请求方法';邮政';不支持_Java_Spring_Spring Mvc - Fatal编程技术网

Java SpringMVC-HTTP状态405-请求方法';邮政';不支持

Java SpringMVC-HTTP状态405-请求方法';邮政';不支持,java,spring,spring-mvc,Java,Spring,Spring Mvc,我已经阅读了所有与这个问题相关的问题,但没有一个解决方案对我有效 我有一个简单的上传表单。 控制器,我不是一个我用过很多次的控制器(但从来没有用于文件上传) 然后我有了上传表单,清理了所有css部分的表单: <form:form method="POST" enctype="multipart/form-data" modelAttribute="uploadedFile"> <input type="hidden" name="$

我已经阅读了所有与这个问题相关的问题,但没有一个解决方案对我有效

我有一个简单的上传表单。 控制器,我不是一个我用过很多次的控制器(但从来没有用于文件上传)

然后我有了上传表单,清理了所有css部分的表单:

<form:form method="POST" enctype="multipart/form-data" modelAttribute="uploadedFile">

         <input type="hidden"
             name="${_csrf.parameterName}"
             value="${_csrf.token}" />
        <form:errors path="*" cssClass="alert alert-danger alert-dismissible"
            element="div" />


            <label class="control-label col-sm-2">Carica
                immagine</label>

                <input type="file" name="file">
                <form:errors path="file" class="control-label" />


        <button id="singlebutton" name="singlebutton"
                        class="btn btn-primary" type="submit">Carica</button>

        </div>
    </form:form>
HTML格式的表单有:

<form id="uploadedFile" class="form-horizontal" action="/smartpark/upload" method="POST" enctype="multipart/form-data">
浏览器网络日志没有说明什么,只是说明POST资源没有完成


感谢您考虑以下事项:

检查您的请求标题,查看它是否正在提交到
floors/upload
。如果没有,请尝试在表单标记中添加action=“floors/upload”属性

尝试将控制器更改为(不使用
路径


查看spring的路径变量

@RequestMapping(value = " /upload/{pathName}", method=RequestMethod.POST)
public String getOrder(@PathVariable String pathName){
 // do what you need
}
我发现了问题。 在此之后,我发现使用spring和CSRF进行多部分文件上载时必须小心处理

所以我首先禁用了CSRF,看看一切是否顺利。之后,我又加了一句

@覆盖
受保护的SpringSecurityFilterChain之前的void(ServletContext ServletContext){
insertFilters(servletContext,新的MultipartFilter());
}

到我的SecurityWebApplicationInitializer.java,这样就不需要身份验证就可以在服务器上上载文件,而只需要将文件移动到最终目的地

然后我必须配置filterMultipartResolver,一切都很顺利


谢谢大家

IntelliJ建议我在旁注中使用
。您可以在类
@Controller@requestmapping(“floors”)公共类上使用requestmapping注释。。。这样,您就不必在每个方法上都有一个冗余常量打开调试日志,检查Spring注册为处理程序方法的内容。打开浏览器的网络日志并检查请求中发送的内容。发布所有内容。安全堆栈中的某些内容正在将请求转发到
/smartpark/Access\u Denied
.mmmm。。。可能是因为
DEBUG CsrfFilter:106-发现无效的CSRF令牌
,即使我将其与表单一起传递…我建议使用以下指南从头开始重新编码:。可能比试图找出你错在哪里要快。从超级简单的东西开始,然后在不破坏它的情况下进行扩展。我使用了@shinjw的建议,但我得到了相同的错误,表单的HTML转到了
,因此看起来它指向了正确的位置…是的,我更新了问题以反映他的建议我已经做了,谢谢。我将所有内容都放在根级别,现在它指向/直接上载的映射if(result.hasErrors())的行是什么?可能这会导致该方法跳过上载内容,你是说这就是问题所在?
<form id="uploadedFile" class="form-horizontal" action="/smartpark/upload" method="POST" enctype="multipart/form-data">
2015-12-22 18:52:13 DEBUG FilterChainProxy:324 - /upload at position 1 of 13 in additional filter chain; firing Filter: 'WebAsyncManagerIntegrationFilter'
2015-12-22 18:52:13 DEBUG FilterChainProxy:324 - /upload at position 2 of 13 in additional filter chain; firing Filter: 'SecurityContextPersistenceFilter'
2015-12-22 18:52:13 DEBUG HttpSessionSecurityContextRepository:192 - Obtained a valid SecurityContext from SPRING_SECURITY_CONTEXT: 'org.springframework.security.core.context.SecurityContextImpl@468e6d7e: Authentication: org.springframework.security.authentication.RememberMeAuthenticationToken@468e6d7e: Principal: org.springframework.security.core.userdetails.User@62dd304: Username: mario; Password: [PROTECTED]; Enabled: true; AccountNonExpired: true; credentialsNonExpired: true; AccountNonLocked: true; Granted Authorities: ROLE_ADMIN; Credentials: [PROTECTED]; Authenticated: true; Details: org.springframework.security.web.authentication.WebAuthenticationDetails@7798: RemoteIpAddress: 192.168.3.38; SessionId: null; Granted Authorities: ROLE_ADMIN'
2015-12-22 18:52:13 DEBUG FilterChainProxy:324 - /upload at position 3 of 13 in additional filter chain; firing Filter: 'HeaderWriterFilter'
2015-12-22 18:52:13 DEBUG HstsHeaderWriter:128 - Not injecting HSTS header since it did not match the requestMatcher org.springframework.security.web.header.writers.HstsHeaderWriter$SecureRequestMatcher@26ee04e5
2015-12-22 18:52:13 DEBUG FilterChainProxy:324 - /upload at position 4 of 13 in additional filter chain; firing Filter: 'CsrfFilter'
2015-12-22 18:52:13 DEBUG CsrfFilter:106 - Invalid CSRF token found for http://192.168.3.240:8080/smartpark/upload
2015-12-22 18:52:13 DEBUG DispatcherServlet:861 - DispatcherServlet with name 'dispatcher' processing POST request for [/smartpark/Access_Denied]
2015-12-22 18:52:13 DEBUG RequestMappingHandlerMapping:306 - Looking up handler method for path /Access_Denied
2015-12-22 18:52:13 DEBUG ExceptionHandlerExceptionResolver:133 - Resolving exception from handler [null]: org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'POST' not supported
2015-12-22 18:52:13 DEBUG ResponseStatusExceptionResolver:133 - Resolving exception from handler [null]: org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'POST' not supported
2015-12-22 18:52:13 DEBUG DefaultHandlerExceptionResolver:133 - Resolving exception from handler [null]: org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'POST' not supported
2015-12-22 18:52:13 WARN  PageNotFound:208 - Request method 'POST' not supported
2015-12-22 18:52:13 DEBUG DispatcherServlet:1034 - Null ModelAndView returned to DispatcherServlet with name 'dispatcher': assuming HandlerAdapter completed request handling
2015-12-22 18:52:13 DEBUG DispatcherServlet:1000 - Successfully completed request
2015-12-22 18:52:13 DEBUG HttpSessionSecurityContextRepository$SaveToSessionResponseWrapper:211 - Skip invoking on
2015-12-22 18:52:13 DEBUG SecurityContextPersistenceFilter:105 - SecurityContextHolder now cleared, as request processing completed
 @RequestMapping(value="upload", method=RequestMethod.POST)
@RequestMapping(value = " /upload/{pathName}", method=RequestMethod.POST)
public String getOrder(@PathVariable String pathName){
 // do what you need
}
<html xmlns:form="http://www.w3.org/1999/xhtml">