• 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

servlets: can we override service method ?if yes how and why?if no then why?

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i hav few doubts in servlets
1)servlets can have user defined methods then how we can call them from other servlet
2)if servlets have session and context how we can we can call the userdefined methods
3)how we can override service method
 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sashidhar,

Servlets are designed to be invoked to handle an HttpServletRequest. The servlet engine responds to requests by invoking the service method, which delegates to either doGet or doPost depending on the type of HTTP request.

So when we create a servlet we extend the HttpServlet class and typically override the doGet and doPost methods. We may delegate from either of these methods to other methods in our servlet but our servlet would be invoked via the service method invoking either doGet or doPost.

Firstly, methods in a servlet other than those that are being overridden should be private.

Secondly, methods other than those being overridden should only be called within the servlet.

Thirdly, the service method is not designed to be overridden.

I hope this helps.
[ September 23, 2005: Message edited by: Keith Pitty ]
 
Sashidhar Rao Gopisetty
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Keith Pitty

how we can call the userdifined methods of one servlet from another servlet
 
Keith Pitty
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What do you mean by a user-defined method?
 
Keith Pitty
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you want to call one servlet from another the technique is:

This forwards a request, response pair from the first servlet to the second where "/SecondServlet" is the servlet mapping defined in the deployment descriptor (web.xml) to the second servlet.

Does this help?
 
Sashidhar Rao Gopisetty
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
other than post get service ,some public methods to be used in servlet
 
Keith Pitty
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Servlets are not designed to be invoked via public methods directly. The Servlet API is designed to provide a way for Java to handle HTTP requests. This is why the service method delegates to doGet or doPost.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic