aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Static and Dynamic including of JSP 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 "Static and Dynamic including of JSP" Watch "Static and Dynamic including of JSP" New topic
Author

Static and Dynamic including of JSP

Ganesh.P Ram
Ranch Hand

Joined: Dec 22, 2005
Posts: 41
Hi folks,
This is my first posting in Java Ranch..
Could some body explain as to what is the difference between static and dynamic including of a jsp ..

Thanks in advance,
Ganesh


Ganesh
Marcelo Ortega
Ranch Hand

Joined: May 31, 2005
Posts: 519

Hi Ganesh,

I'm going to assume you are refering to the difference between the <jsp:include> standard action and the include directive.

<jsp:include page="somePage.jsp" /> -- dynamic
The above standard action includes a page at runtime (a RequestDispatcher is obtained and the include() method is invoked). This is a bit slower than the directive because it includes the reponse of the included file at runtime.

<%@ include file="somePage.jsp" %> -- static
The include directive inserts the contents of the included file (somePage.jsp) at translation time (in other words, when the container turns your jsp into a servlet). This is considerd the way apropriate when the included contents is not likely to change.

Regards, Marzo.
[ January 15, 2006: Message edited by: Marzo Kaahn ]

SCJP 1.4, SCWCD 1.4, SCBCD 1.3, SCJD, SCEA/OCMJEA

Live life to an interface, not an implementation!
Ganesh.P Ram
Ranch Hand

Joined: Dec 22, 2005
Posts: 41
Hi Marzo,
Thanks for ur reply.
I have one more related doubt.
Assume i have a.jsp.
In this, I include b.jsp.

And there are some common parameters in both the jsp.
In this case I think that, at translation time, it would cause some problem because there would be duplicated variables in the servlet.
Is this the case for both static and dynamic include or are there any exceptions ?

Ganesh
Marcelo Ortega
Ranch Hand

Joined: May 31, 2005
Posts: 519

If the include directive (the static way) is used, you can use a variable that is not declared in the included page but is declared in the page that includes it, because there is no problem, given that once translated, the included contents will have access the the declared variable.

If the jsp standard action is used, the variable must be declared in the included page, given that it is the response (result) which gets added, so it should have it's own variables (unless of course you pass a parameter to the included file).

Best regards, Marzo.
[ January 16, 2006: Message edited by: Marzo Kaahn ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Static and Dynamic including of JSP