如何修复“org.springframework.web.HttpRequestMethodNotSupportedException : Request method 'POST' not supported?" [英] How to fix "org.springframework.web.HttpRequestMethodNotSupportedException : Request method 'POST' not supported ?"
本文介绍了如何修复“org.springframework.web.HttpRequestMethodNotSupportedException : Request method 'POST' not supported?"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以我收到警告
WARN [org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver] (default task-2) Resolved [org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'POST' not supported]
当我访问以下网址时 http://localhost:8080/ProjectFE/uregistration
并且网站显示
when I go to the following URL http://localhost:8080/ProjectFE/uregistration
and the website shows
不允许使用 HTTP 405 方法
HTTP 405 Method not allowed
这是我的控制器代码:
package controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import model.daoimpl.UserinfoDaoImpl;
import model.dao.IUserinfoDAO;
import model.entity.Userinfo;
@Controller
public class RegistrationController {
@RequestMapping(value="/registration",method = RequestMethod.GET)
public String addRegistrationPage() {
return "registrationpage";
}
@RequestMapping(value="/uregistration",method = RequestMethod.POST)
public String addURegistrationPage(@ModelAttribute("User")Userinfo u) {
IUserinfoDAO iu = new UserinfoDaoImpl();
boolean b = iu.insertInfo(u);
if(b)
return "success";
else
return "registrationpage";
}
}
那我该怎么办?另外,如果需要任何其他代码,请评论我将编辑帖子,谢谢.
So what should I do ? Also if any other code is required please comment I'll edit the post, Thankyou.
推荐答案
对于那些我们有相关问题的人,当我使用带有空格的 @PathVariable 而不是 @RequestBody 发帖时遇到了这个问题
For those we have a related issue, I had this problem when I post using a @PathVariable with space in it rather than @RequestBody
这篇关于如何修复“org.springframework.web.HttpRequestMethodNotSupportedException : Request method 'POST' not supported?"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文