File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Include Statements Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Include Statements" Watch "Include Statements" New topic

Include Statements

Corey McGlone
Ranch Hand

Joined: Dec 20, 2001
Posts: 3271
I've been reading through HFS&J and I came up with a question while I was going through the review regarding the include page directive and the include standard action.

Let's say I use an include directive in my file A.jsp, which includes the file B.jsp. The first time A.jsp is requested, the contents of B.jsp are copied into A.jsp and the resulting file is then translated into a Java Servlet. Obviously, as servlets are only translated once, if I then change B.jsp and request A.jsp, I don't see the new changes because A.jsp has already been translated. (Granted, I believe the text says that some containers can catch that.)

However, with the <jsp:include> standard action, I'm a little confused. Once again, let's say I'm including B.jsp in A.jsp, but this time, I'll use a standard action to perform the inclusion. The first time A.jsp is requested, it is translated into a servlet - that servlet contains a forward to B.jsp. When this servlet's service method is executed, it forwards the request to B.jsp, which also needs to be translated and initialized. When B.jsp has completed its service method, execution returns to A.jsp's service method.

Now, if I change B.jsp at this point, would I see the change? If B.jsp has already been translated into a servlet, would the container automatically re-translate it when B.jsp is included via A.jsp again? I assumed that, once B.jsp has been translated, it would never be translated again (until it was redeployed). However, in the summary, the text states:

The <jsp:include> standard action includes the response of the included page into the original page at runtime. So the include standard action is considered appropriate for including content that may be updated after deployment, while the include directive is not.

That statement leads me to believe that every time B.jsp is included in A.jsp (via standard action, not directive), B.jsp is retranslated and initialized. If that's the case, how big of a performance hit is this on real-world systems?


SCJP Tipline, etc.
Nicholas Cheung
Ranch Hand

Joined: Nov 07, 2003
Posts: 4982
There are 2 ways to include a JSP: static include vs dynamic include.

If you include the page using directive, it is regarded as static include, and it is done in complication time.

If you include the page using action tag, it is regarded as dynamic include, and it is done in runtime.

Thus, you find that, if you change something. For static include, the changes do not reflect even you reload the page, however, for dynamic include, the changes DO reflect.

I think this will not be a problem becos only modified page will trigger the recomplication.



SCJP 1.2, OCP 9i DBA, SCWCD 1.3, SCJP 1.4 (SAI), SCJD 1.4, SCWCD 1.4 (Beta), ICED (IBM 287, IBM 484, IBM 486), SCMAD 1.0 (Beta), SCBCD 1.3, ICSD (IBM 288), ICDBA (IBM 700, IBM 701), SCDJWS, ICSD (IBM 348), OCP 10g DBA (Beta), SCJP 5.0 (Beta), SCJA 1.0 (Beta), MCP(70-270), SCBCD 5.0 (Beta), SCJP 6.0, SCEA for JEE5 (in progress)
I agree. Here's the link:
subject: Include Statements
It's not a secret anymore!