• 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

Overriding the doPost method

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 2856
10
Firefox Browser Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Calling doPost from doGet or vice versa is very common.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic