This week's book giveaway is in the HTML Pages with CSS and JavaScript forum.
We're giving away four copies of Testing JavaScript Applications and have Lucas da Costa on-line!
See this thread for details.
Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Can we Have Write Service,doGet,doPost method implementation in a single servlet

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a class Called LoginServlet
I Implemented
--doGet()
--doPost()
--Service()
Methods ,So Which method will called when i request for it?
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Which method will called when i request for it?



Service will never be called. GET or POST requests will go to doGet or doPost.

Pehaps you were thinking about overriding the service( request, response) method but Service will not do that since Java is case sensitive.

IF you had overriden service() correctly, it would get all requests since the default service that routes requests to doGet etc..

Bill
 
Marshal
Posts: 67425
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Never override service(). (Unless you have a really good reason to, which you probably do not.)
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
doGet() or doPost() methods will be called based on what method you define in the jsp/html i.e. if you define method="post", doPost() will be called, and if you define method="get", doGet() will be called.
And again there is easiest way to find out what is getting called when, by using either debugger or logs
 
Bear Bibeault
Marshal
Posts: 67425
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Shuki", please check your private messages for an important administrative matter.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
service() method will be called first.
If you make an explicit call to doget() method from the service method then goGet() method runs.

For Example:





Output:

Servlet TestServlet at /Servlets------GET

If we modify the service method



Output:

doGet runs
doPost runs
Servlet TestServlet at /Servlets------GET
 
Bartender
Posts: 4107
72
Hibernate Fedora Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Swarna Kota wrote:Output:
Servlet TestServlet at /Servlets------GET


Why do you think you got that output? Just read the replies above to get an idea. You should not override the "service()" method. This post is almost two years old anyway. If you have any doubt you may start a new thread on your own.
And Welcome to JavaRanch

 
Sheriff
Posts: 6631
1254
IntelliJ IDE jQuery Eclipse IDE Postgres Database Tomcat Server Chrome Google App Engine
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Swarna, please UseCodeTags when you post a source code in future. I added code tags for you.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    Bookmark Topic Watch Topic
  • New Topic