• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

HTTP Status 405 - Request method 'GET' not supported

 
Ranch Hand
Posts: 114
Hibernate Eclipse IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear All,
I am implementing a Spring MVC based application and i am using spring 3.2.x I wrote my logout controller as folllows:

I am calling this controller on the click of a link in my home page as follows:


When i hit the logout link in my firefox browser i see the following message:


I am not able to make out what the problem is. Please help
 
Rancher
Posts: 989
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The anchor tag will always do a GET (there is no way to specify GET or POST). If you still want to use the anchor tag then you would need to use Javascript like or use an and style it using css to look the same way as you wanted the anchor to look.
 
Deepaks Deshpande
Ranch Hand
Posts: 114
Hibernate Eclipse IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear E Armitage,

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:
<a href="logout.htm">Logout</a>.

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.
 
E Armitage
Rancher
Posts: 989
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Bartender
Posts: 1682
7
Android Mac OS X IntelliJ IDE Spring Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Bill Gorder
Bartender
Posts: 1682
7
Android Mac OS X IntelliJ IDE Spring Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Deepaks Deshpande
Ranch Hand
Posts: 114
Hibernate Eclipse IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Bill.I got it now. I did change my JSP code. Now I am using a button for logout and it is working for the POST method
reply
    Bookmark Topic Watch Topic
  • New Topic