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

They’re NOT the same underneath...

The <jsp:include /> standard action and the include directive look the same, and often give the same result, but take a look at the generated servlets. We took this code directly out of the _jspService() method from Tomcat’s generated servlet code...

Generated servlet code for the header file

out.write("\r<html>\r<body>\r<img src=\"images/Web-Services.jpg\" >
     <br>\r<em><strong>We know how to make SOAP suck less.</strong></em> <br>\r\r
     </body>\r</html>\r");

Note

Simple... it just does the output.

Generated servlet for the JSP using the include directive

out.write("<html><body>\r");

out.write("\r<html>\r<body>\r<img src=\"images/Web-Services.jpg\" >
     <br>\r<em><strong>We know how to make SOAP suck less.</strong></em> <br>\r\r
     </body>\r</html>\r");

out.write("\r<br>\r\r\r<em>We can help.</em> <br><br>\r\rContact us at: ");
out.write((java.lang.String) org.apache.jasper.runtime.PageContextImpl.
     proprietaryEvaluate("${initParam.mainEmail}", java.lang.String.class,
      (PageContext)_jspx_page_context, null, false));

out.write("\r\r\r</body></html>");

Note

This part in bold is EXACTLY the same as the Header.jsp page generates.

Note

The include directive just takes the contents of the “Header.jsp” file and places it into the “Contact.jsp” page BEFORE it does the translation!

Generated servlet for the JSP using the <jsp:include /> standard action

Note

This is different! The original Header.jsp file is NOT inside the generated servlet. Instead, it’s some kind of runtime call... ...

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