Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

HTTP Status 405 - HTTP method POST is not supported by this URL  RSS feed

 
Ryan McClain
Ranch Hand
Posts: 153
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have read about this error on the forums and I know it's fairly simple to fix but I haven't been able to fix it.

We all know the error and we know that possible fixes are:
- override doGet, doPost
- recompile classes and throw old ones away

cookietest.html


CookieTest Servlet:


cookieresult.jsp


CheckCookie Servlet


web.xml


What I do is the following:
1. visit http://localhost:xx/cookieTest/cookietest.html, fill in name in the form, click on submit button

Then I get the error:
http://localhost:xx/cookieTest/cookietest.do
HTTP Status 405 - HTTP method POST is not supported by this URL

Manually visiting cookietest.do gives me a blank page.

This strikes me as bizarre, because I have overwritten the doPost() method in the CookieTest servlet. /cookietest.do is pointing to CookieTest which is pointing to CookieTest.class and I recently updated my classes to confirm this.
So CookieTest is being hit, yet it's saying that POST is not supported? I don't understand.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66142
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you restarted the app?
 
Ryan McClain
Ranch Hand
Posts: 153
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Many times over, yes. Even killed the Tomcat instance and restarted it various times as well.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66142
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmm, then I'm not seeing anything suspicious on inspection.

P.S. It's usually a good idea to use the @Override annotation, as it points out when you haven't overridden correctly. But I'm not seeing an issue here.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66142
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your servlet mapping has 2 entries. Not valid. Split them up and see if things improve.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66142
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would also highly recommend improving your action paths. Page-relative addressing is fragile and only works by accident in this instance.
 
Ryan McClain
Ranch Hand
Posts: 153
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Splitting up the <servlet-mapping> elements has fixed it.

Result:


My interpretation of this is that perhaps the Container got confused and applied the CheckCookie class as the <servlet-name> for /cookietest.do. Perhaps like this:
<servlet-name>CookieTest</servlet-name>
-> Ok, the servlet of choice is CookieTest
<url-pattern>/cookietest.do</url-pattern>
-> Ok, that's the URL
<servlet-name>CheckCookie</servlet-name>
-> Another servlet-name? I guess he wants to overwrite it. Ok, servlet-name is now CheckCookie and I will match the <url-pattern> to that class.
-> Now both <url-pattern> elements belong to the CheckCookie class.

I am just speculating here. It would be nice to know how Tomcat really got confused behind the scenes.

 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66142
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm surprised it didn't just refuse to load the web app. When your deployment descriptor is invalid, all bets are off.
 
Ivan Jozsef Balazs
Rancher
Posts: 999
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You've got doGet but no doPost: no wonder POST is not supported by the servlet.

 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ivan Jozsef Balazs wrote:You've got doGet but no doPost: no wonder POST is not supported by the servlet.

There are two servlets - the one that caused the issue had both methods.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!