Why SpringMVC Request method 'GET' not supported?

前端 未结 6 574
误落风尘
误落风尘 2020-12-01 05:34

I trying @RequestMapping(value = \"/test\", method = RequestMethod.POST) but is error

Code is

 @Controller
 public class HelloWordContr         


        
相关标签:
6条回答
  • 2020-12-01 05:48

    if You are using browser it default always works on get, u can work with postman tool,otherwise u can change it to getmapping.hope this will works

    0 讨论(0)
  • 2020-12-01 05:54

    Change

    @RequestMapping(value = "/test", method = RequestMethod.POST)
    

    To

    @RequestMapping(value = "/test", method = RequestMethod.GET)
    
    0 讨论(0)
  • 2020-12-01 05:56

    I solved this error by including a get and post request in my controller: method={RequestMethod.POST, RequestMethod.GET}

    0 讨论(0)
  • 2020-12-01 06:05

    method = POST will work if you 'post' a form to the url /test.

    if you type a url in address bar of a browser and hit enter, it's always a GET request, so you had to specify POST request.

    Google for HTTP GET and HTTP POST (there are several others like PUT DELETE). They all have their own meaning.

    0 讨论(0)
  • 2020-12-01 06:06

    Apparently some POST requests looks like a "GET" to the server (like Heroku...)

    So I use this strategy and it works for me:

    @RequestMapping(value = "/salvar", method = { RequestMethod.GET, RequestMethod.POST })
    
    0 讨论(0)
  • 2020-12-01 06:09

    I also had the same issue. I changed it to the following and it worked.

    Java :

    @RequestMapping(value = "/test", method = RequestMethod.GET)
    

    HTML code:

      <form action="<%=request.getContextPath() %>/test" method="GET">
        <input type="submit" value="submit"> 
        </form>
    

    By default if you do not specify http method in a form it uses GET. To use POST method you need specifically state it.

    Hope this helps.

    0 讨论(0)
提交回复
热议问题