[英]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.