Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Overriding the doPost method

 
B Crosthwaite
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,

Im am going over my old webdev tutorials and i have got stuck. Hopefully i might get some help here

this is the code:


What i am trying to do is override the doPost method with a doGet method. The code above will compile but i get the HTTP error 405.

Does anyone see where i am going wrong?

Thanks
-Ben
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34178
340
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ben,
You haven't defined doGet. So you are calling the superclass' implementation. I vaguely recall that implementation returning an error code so by default it doesn't do anything. You might try removing the doGet call and seeing if it helps.
 
Amit Ghorpade
Bartender
Posts: 2854
10
Fedora Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want to support both the doGet() and doPost() methods, a better alternative is write a different method say processRequest() and write all your request handling code in that method.Then simply call that method from doGet() and doPost() as well.


Hope this helps
 
B Crosthwaite
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey,

Thanks for you replies. I read some post on the interweb and i modified my code a little bit and came up with this:



This does the job with both get and post from the HTML page.

I was just wondering if this was the best way of going about this certain task? or is there a more efficient way?

Thanks,
-Ben
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Calling doPost from doGet or vice versa is very common.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic