春季mcv不支持请求方法'POST'
问题描述:
我正在使用spring mvc,当我点击它所表示的按钮时,我无法获得按钮来工作:Request method'Post'not supported。春季mcv不支持请求方法'POST'
这是我的html文件:
<html>
<head>
<title>Cart</title>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
</head>
<body th:object="${picture}">
<form method="post">
Authhor: <label th:text="*{ownerName}" /><br />
Title: <label th:text="*{title}" /><br />
Description: <label th:text="*{description}" /><br />
Price: €<label th:text="*{price}" /><br />
Product: <select th:field="${productss}" th:remove="all-but-first">
<option th:each="product : ${productss}"
th:value="${product.id}" th:text="${product.name + ' (+ €' + product.price + ')'}">Productname</option>
</select><br />
<img width="250" heigth="250" th:src="*{plainURL}"/><br />
<button align="right" class="btn" type="submit" name="add" ><span class="glyphicon glyphicon-check">Add to shopping cart</span></button><br />
</form>
</body>
</html>
这是我要执行的方法:
@RequestMapping(value = IMAGE, method = RequestMethod.POST, params = {"add"})
public String add(HttpSession session, Model model) {
System.out.println("its working!");
return "/image/5";
}
我知道这questen张贴了很多,但我不能找到一个为我工作的解决方案。
答
您尚未为表单指定任何目标。在“@RequestMapping
”中添加“操作”和添加的路径。为您的价值添加“双引号”。
@RequestMapping(value = "image", method = RequestMethod.POST, params = {"add"})
如果你不提你的形式action
,它将目前打网址在浏览器地址栏。在这种情况下,url也应该能够处理帖子。例如,如果您有localhost/app/addTocart
,那么您应该处理两种方法。与method=post
和其他method=get
以形式'