O'Reilly logo

Head First Servlets and JSP, 2nd Edition by Bert Bates, Bryan Basham, Kathy Sierra

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time to see the REAL generated servlet

We’ve been looking at a super-simplified version of the servlet the Container actually creates from your JSP. There’s no need to look at the Container-generated code during development, but you can use it to help learn. Once you’ve seen what the Container does with the different elements of a JSP, you shouldn’t need to ever look at the Container-generated .java source files. Some vendors won’t let you see the generated Java source, and keep only the compiled .class files.

Don’t be intimidated when you see parts of the API that you don’t recognize. Most of the class and interface types are vendor-specific implementations you shouldn’t care about.

What the Container does with your JSP

  • Looks at the directives, for information it might need during translation.

  • Creates an HttpServlet subclass.

    For Tomcat 5, the generated servlet extends:

    org.apache.jasper.runtime.HttpJspBase

  • If there’s a page directive with an import attribute, it writes the import statements at the top of the class file, just below the package statement.

    For Tomcat 5, the package statement (which you don’t care about) is: package org.apache.jsp;

  • If there are declarations, it writes them into the class file, usually just below the class declaration and before the service method. Tomcat 5 declares one static variable and one instance method of its own.

  • Builds the service method. The service method’s actual name is _jspService(). It’s called by the servlet superclass’ overridden service() method, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required