• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Overriding the doGet and doPost Methods in servlet

 
Rachit Kumar Saxena
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65120
91
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Rachit Kumar Saxena
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How does the service() method know which method to invoke?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65120
91
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It inspects the request for the HTTP method type.
 
Kunal Lakhani
Ranch Hand
Posts: 622
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic