2017-10-10 3 views
0

스프링 mvc를 사용하고 있는데 버튼을 클릭하면 작동 할 수 없습니다. 요청 방법 'Post'가 지원되지 않습니다. 요청 방법 'POST'는 Spring mcv에서 지원되지 않습니다.

내 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

'

' –

답변

0

양식의 대상을 지정하지 않았습니다. "작업"과 추가 한 경로를 @RequestMapping에 추가하십시오. 귀하의 가치에 "큰 따옴표"를 추가하십시오. 당신이 당신의 형태로 action을 언급하지 않는 경우

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

, 귀하의 브라우저 URL 표시 줄에 현재 URL에 타격을 줄 것으로 예상된다. 이 경우 URL은 게시물을 처리 할 수 ​​있어야합니다. 예를 들어, localhost/app/addTocart이 있다면 두 가지 방법을 사용해야합니다. method=post 및 기타로 method=get

관련 문제