This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes service() and _jspService() methods Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "service() and _jspService() methods" Watch "service() and _jspService() methods" New topic
Author

service() and _jspService() methods

vidula kulkarni
Greenhorn

Joined: May 24, 2001
Posts: 18
How does the servlet container differentiate between service() and _jspService() methods?
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
When the JSP file is processed to generate a Servlet, the JSP processor makes one which conforms to the Servlet API specification, and thus includes a "service" method. Depending on the particular JSP implementation it can do that by inheriting from some generic JSPServlet class or by actually coding it all in the generated servlet. This method does some stuff, then calls a _jspService method. which is also generated in the same way.
As far as the container is concerned, there is only a "service" method, and that's what it calls.


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
vidula kulkarni
Greenhorn

Joined: May 24, 2001
Posts: 18
Thanks!! But can u elaborate more?<br> When a jsp is complied,the generated servlet has the _jspService() mtd.There is no implementation for the service() method.
Simon Brown
sharp shooter, and author
Ranch Hand

Joined: May 10, 2000
Posts: 1913
    
    6
The translated JSPs (Servlets) generally extend a container specific superclass where all this sort of stuff is implemented.
Simon
Maha Annadurai
Ranch Hand

Joined: Oct 27, 2002
Posts: 87
The container generated servlet class implements interface 'HttpJspPage' which extends 'JspPage' which in turn extends 'Servlet' interface.
Servlet
1. init(config)
2. public service(req, res)
3. destroy() and others
JspPage extends Servlet and adds
1. jspInit()
2. jspDestroy()
HttpJspPage extends JspPage and adds
1. _jspService(req,res)
So essentially the generated servlet implements all the above listed methods. Some containers have a superclass which has all the above methods implementations done already. The only one method which is generated at the time our jsp's servlet is compiled is, the _jspService(req,res) which is added on the fly during compilation.
As far as the container is concerned, it calls the public Service(req,res) method only. This public service(req,res) method in turn calls _jspService(req,res) in generated servlet.
Regards,
Maha Anna
 
jQuery in Action, 2nd edition
 
subject: service() and _jspService() methods
 
Similar Threads
JSP Base class
How does a JSP inherit getServletContext() & getServletConfig methods?
jsp translate servlet method problem
jsp code compilation error
pre compilation of JSP file