But how did spring support a POST with earlier versions prior to 2.5 where annotations weren't used? For example with the SimpleFormController. Even then i used the anchor element's href attribute to specify the link as follows:
Can you please give me a detailed explanation on this. (I have coded the logout link similarly in the above snippet also)
Note:I am showing this piece of code without the code tags because the href and the code following it are not displayed with in the code tags.
I'm not sure I understand the question fully but if you are saying that this worked previously when the annotation was not there then perhaps the controller was supporting both GET and POST and so the GET call was being allowed? Note, it's usually a bad idea to treat GET request the same as POST requests.
SimpleFormController is very old and the current hander mapping approach you should be using can't even really be compared to that easily. I would forget about SimpleFormControllers and focus on understanding the current way to do it.
When Spring registers this Controller bean it will scan it for @RequestMapping methods. These methods can define certain attributes to narrow down which method is the 'best' match for the request. The first obvious match is the URL which you have in the value. After that you have specified a request method of POST. What this means is only execute this method if a request comes in for /logout.htm and only if it an HTTP POST. In your case your were hitting that URL but it was an HTTP GET because you were clicking a link not submitting a form. This is what E Armitage was trying to point out to you. So the solution is either to change the controller to expect a HTTP GET or to change your JSP to call the server using and HTTP POST.
E Armitage wrote:I'm not sure I understand the question fully but if you are saying that this worked previously when the annotation was not there then perhaps the controller was supporting both GET and POST and so the GET call was being allowed? Note, it's usually a bad idea to treat GET request the same as POST requests.
You are correct if the RequestMethod is not defined it does not factor it into whether or not the method matches. In other words GET and POST will match it.