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

What REALLY happens to your JSP code?

You write a JSP, but it becomes a servlet. The only way to really tell what’s happening is to look at what the Container does to your JSP code. In other words, how does the Container translate your JSP into a servlet?

Once you know where different JSP elements land in the servlet’s class file, you’ll find it much easier to know how to structure your JSP.

The servlet code on this page is not the real code generated by the Container—we simplified it down to the essential parts. The Container-generated servlet file is, well, uglier. The real generated servlet source code is slightly harder to read, but we will look at the real thing in a few pages. For now, though, all we care about is where in the servlet class our JSP code actually ends up.

image with no caption

Note

ALL scriptlet and expression code lands in a service method.

That means variables declared in a scriptlet are always LOCAL variables!

Note

Note: if you want to see the generated servlet code from Tomcat, look in yourTomcatHomeDir/work/Catalina/yourServerName/yourWebAppName/org/apache/jsp. (The underlined names will change depending on your system and your web app.)

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