2017-10-10 83 views
0

我正在使用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張貼了很多,但我不能找到一個爲我工作的解決方案。

+2

以形式'

添加一個'action'屬性' –

回答

0

您尚未爲表單指定任何目標。在「@RequestMapping」中添加「操作」和添加的路徑。爲您的價值添加「雙引號」。

@RequestMapping(value = "image", method = RequestMethod.POST, params = {"add"}) 

如果你不提你的形式action,它將目前打網址在瀏覽器地址欄。在這種情況下,url也應該能夠處理帖子。例如,如果您有localhost/app/addTocart,那麼您應該處理兩種方法。與method=post和其他method=get

相關問題