简体   繁体   English

HTTP状态405-不支持请求方法“ POST”

[英]HTTP Status 405 - Request method 'POST' not supported

I am using spring, spring security, hibernate. 我正在使用Spring,Spring Security,Hibernate。 Got a jsp page where i am trying to upload a file, and backend ai have a controller to capture and store the file uploaded. 在我试图上载文件的jsp页面上,后端ai有一个控制器来捕获和存储上载的文件。 I am using tomcat. 我正在使用tomcat。 I am using spring security for login authentication. 我正在使用Spring Security进行登录身份验证。 Getting the following error when i upload the file HTTP Status 405 - Request method 'POST' not supported Any ideas? 我上载文件HTTP状态405时遇到以下错误-请求方法'POST'不支持任何想法?

You will need to ensure your request handler is able to accept a POST. 您将需要确保您的请求处理程序能够接受POST。 You can also configure Spring to use a MultipartResolver to aid you in getting your request parts. 您还可以配置Spring以使用MultipartResolver来帮助您获取请求零件。

Configuration of MultiPartResolver MultiPartResolver的配置

@Bean(name = "mulitpartResolver")
public MultipartResolver multipartResolver() {
    if (multipartResolver == null) {
        multipartResolver = new CommonsMultipartResolver();
    }
    return multipartResolver;
}

Here is the request mapping: 这是请求映射:

@RequestMapping(method = RequestMethod.POST, value = "/some/post/url")
public void postFile(MultipartHttpServletRequest request) {
    MultipartFile multipartFile = request.getFileMap().get("keyForFileInFormPost");
    ...
}

Note, that sometimes this will not work with Spring Security. 请注意,有时这不适用于Spring Security。 You can look at my blog post here on using multipartrequestresolvers with spring security for help: 您可以在这里查看我的博客文章,其中涉及如何使用具有弹簧安全性的multipartrequestresolvers寻求帮助:

http://www.adamweigold.com/2012/01/using-multpartrequestresolvers-with.html http://www.adamweigold.com/2012/01/using-multpartrequestresolvers-with.html

Just define bean "multipartResolver" in your Spring Context 只需在您的Spring Context中定义bean“ multipartResolver”

    <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
        <!-- one of the properties available; the maximum file size in bytes -->
        <property name="maxUploadSize" value="2097152"/>
    </bean>

And use 并使用

@ResponseBody
@RequestMapping(value = "/{tenantId}/getEntityInfo", method = RequestMethod.POST)
public ResponseEntity<String> getEntityInfo(
        @RequestParam(value = "xml", required = false) MultipartFile xml) {
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 HTTP状态405-Spring MVC不支持请求方法&#39;POST&#39; - HTTP Status 405 - Request method 'POST' not supported Spring MVC spring-security:HTTP状态405-不支持请求方法“ POST” - spring-security:HTTP Status 405 - Request method 'POST' not supported Spring Security过滤器,HTTP状态405-不支持请求方法“ POST” - Spring Security filter, HTTP Status 405 - Request method 'POST' not supported spring security 4.0.1 - HTTP状态405 - 不支持请求方法“POST” - spring security 4.0.1 - HTTP Status 405 - Request method 'POST' not supported Spring Social Twitter HTTP状态405-不支持请求方法“ POST” - Spring Social Twitter HTTP Status 405 - Request method 'POST' not supported HTTP状态405 - 不支持请求方法&#39;POST&#39; - Spring Security - HTTP Status 405 - Request method 'POST' not supported - Spring Security HTTP 状态 405 - 不支持请求方法“POST”(Spring MVC) - HTTP Status 405 - Request method 'POST' not supported (Spring MVC) 编辑时:HTTP状态405-请求方法&#39;POST&#39;不支持 - While editing: HTTP Status 405 - Request method 'POST' not supported 获取HTTP状态405-不支持请求方法“ POST” - getting HTTP Status 405 - Request method 'POST' not supported Spring MVC - HTTP 状态 405 - 不支持请求方法“POST” - Spring MVC - HTTP Status 405 - Request method 'POST' not supported
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM