aspose file tools*
The moose likes Servlets and the fly likes Overriding the doGet and doPost Methods in servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Overriding the doGet and doPost Methods in servlet" Watch "Overriding the doGet and doPost Methods in servlet" New topic
Author

Overriding the doGet and doPost Methods in servlet

Rachit Kumar Saxena
Ranch Hand

Joined: Dec 24, 2011
Posts: 50
In a servlet after extending the HttpServlet class,if I override the doGet or doPost Methods,what is difference in functioning?What happens if code meant to be written in doGet is written in doPost because I read that the service methods calls the doGet or doPost methods,after getting its reference.Please explain.I would like to understand this in depth.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60077
    
  65

If the request is a POST, the doPost() method will be called. If it's a GET, the doGet() method will be called.

If you put the code in the wrong place, the wrong code will execute. Simple as that.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Rachit Kumar Saxena
Ranch Hand

Joined: Dec 24, 2011
Posts: 50
How does the service() method know which method to invoke?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60077
    
  65

It inspects the request for the HTTP method type.
Kunal Lakhani
Ranch Hand

Joined: Jun 05, 2010
Posts: 618
In doGet method, the data sent are appended in the url. So that should not be used when you are working with data you need to secure, like username password in login page.
doGet has limited data, where in doPost you can have large amount of data.


kunal
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Overriding the doGet and doPost Methods in servlet
 
Similar Threads
servlets
HTTP Status 405 - HTTP method GET is not supported by this URL
servlet
doGet and doPost
doGet,doPost