I trying @RequestMapping(value = \"/test\", method = RequestMethod.POST)
but is error
Code is
@Controller
public class HelloWordContr
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
Change
@RequestMapping(value = "/test", method = RequestMethod.POST)
To
@RequestMapping(value = "/test", method = RequestMethod.GET)
I solved this error by including a get and post request in my controller: method={RequestMethod.POST, RequestMethod.GET}
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.
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 })
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.