Jsp 不支持请求的方法POST,Spring MVC JDBCTemplate
获取405错误:Spring MVC JDBCTemplate CRUD操作中不支持请求方法Jsp 不支持请求的方法POST,Spring MVC JDBCTemplate,jsp,spring-mvc,spring-jdbc,Jsp,Spring Mvc,Spring Jdbc,获取405错误:Spring MVC JDBCTemplate CRUD操作中不支持请求方法'POST' 如何解决代码段中不支持的405“POST”方法 使用SpringMVC和JDBCTemplate进行crud操作 访问DELETE语句的URL:/JdbcTemplate/user/DELETE/9 以下是控制器类中的方法: @RequestMapping(value = "/edit/{id}", method = RequestMethod.GET) public ModelAn
'POST'
如何解决代码段中不支持的405“POST”方法
使用SpringMVC和JDBCTemplate进行crud操作
访问DELETE语句的URL:/JdbcTemplate/user/DELETE/9
以下是控制器类中的方法:
@RequestMapping(value = "/edit/{id}", method = RequestMethod.GET)
public ModelAndView editUser(@PathVariable("id") Integer id, ModelMap model) {
ModelAndView mav = new ModelAndView(USER_EDIT_PAGE);
User user = userService.getUserById(id);
// User user = new User();
model.addAttribute("user", user);
model.addAttribute("id", id);
return mav;
}
@RequestMapping(value = "/update", method = RequestMethod.POST)
public String updateUser(@ModelAttribute("user") User user) {
userService.updateUser(user);
return "redirect:/user/list";
}
@RequestMapping(value = "/delete/{id}", method = RequestMethod.GET)
public ModelAndView deleteUser(@PathVariable ("id") Integer id) {
ModelAndView mav = new ModelAndView(USER_LIST_VIEW);
userService.deleteUser(id);
String message = "Team was successfully deleted.";
mav.addObject("message", message);
return mav;
}
现在不确定传递URL时调用的JSP:
list.jsp
用户列表
身份证件
名称
城市
拉链
国
删去
${user.id}
edit.jsp
<%@ include file="/WEB-INF/views/includes/taglibs.jsp" %>
<!doctype html>
<html>
<head>
<c:import url="/WEB-INF/views/includes/meta.jsp" />
</head>
<body>
<div class="container">
<c:if test="${empty user}">
<h3>User not found: ${id}</h3>
</c:if>
<c:if test="${not empty user}">
<h1>Edit User</h1>
<form:form method="POST" action="update" commandName="user">
<form:hidden path="id" />
<div class="form-group">
<form:label path="firstName">First Name:</form:label>
<form:input path="firstName" class="form-control" placeholder="First Name"/>
</div>
<div class="form-group">
<form:label path="lastName">Last Name:</form:label>
<form:input path="lastName" class="form-control" placeholder="Last Name"/>
</div>
<div class="form-group">
<form:label path="city">City:</form:label>
<form:input path="city" class="form-control" placeholder="City"/>
</div>
<div class="form-group">
<form:label path="zip">Zip:</form:label>
<form:input path="zip" class="form-control" placeholder="Zip"/>
</div>
<div class="form-group">
<form:label path="country">Country:</form:label>
<form:input path="country" class="form-control" placeholder="Country"/>
</div>
<button type="submit" class="btn btn-default">Save</button>
</form:form>
</c:if>
<br><a href="/" class="btn btn-primary">Back</a>
</div>
</body>
</html>
找不到用户:${id}
编辑用户
名字:
姓氏:
城市:
邮编:
国家:
拯救
感谢您的关注。控制器只识别访问/delete/{id}:
@RequestMapping(value = "/delete/{id}", method = RequestMethod.GET)
public ModelAndView deleteUser(@PathVariable ("id") Integer id) {
在list.jsp上,您有一个表单向/delete/{id}发送帖子,所以这似乎是问题所在:
<form:form action="${pageContext.request.contextPath}/user/delete/${user.id}" method="POST">
<input type="submit" class="btn btn-danger btn-sm" value="Delete" />
</form:form>
将表单上的方法从POST更改为GET,这将解决您的问题。如果要允许GET和POST到/delete/{id},删除deleteUser上的
@RequestMapping
中的method=RequestMethod.GET
将允许它处理所有HTTP方法,而不仅仅是GET。在删除deleteUser()中的method=RequestMethod.GET
时,没有任何操作或发送的请求不会从表中删除记录方法
<form:form action="${pageContext.request.contextPath}/user/delete/${user.id}" method="POST">
<input type="submit" class="btn btn-danger btn-sm" value="Delete" />
</form:form>