File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Overriding the doPost method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Overriding the doPost method" Watch "Overriding the doPost method" New topic
Author

Overriding the doPost method

B Crosthwaite
Ranch Hand

Joined: Oct 22, 2008
Posts: 39
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
internet detective
Marshal

Joined: May 26, 2003
Posts: 30294
    
150

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.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Amit Ghorpade
Bartender

Joined: Jun 06, 2007
Posts: 2716
    
    6

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


SCJP, SCWCD.
|Asking Good Questions|
B Crosthwaite
Ranch Hand

Joined: Oct 22, 2008
Posts: 39
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

Joined: Dec 11, 2004
Posts: 13410

Calling doPost from doGet or vice versa is very common.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Overriding the doPost method