aspose file tools*
The moose likes JSP and the fly likes include - directive and action Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "include - directive and action" Watch "include - directive and action" New topic
Author

include - directive and action

nirali shah
Greenhorn

Joined: Apr 16, 2009
Posts: 24
<%@ include file="somePageOfText.ext" %>

"The directive tag instructs the JSP compiler to merge contents of the included file into the JSP before creating the generated servlet code. It is the equivalent to cutting and pasting the text from your include page right into your JSP. "

This includes file somePageOfText.ext in the page. Question is, does it get the content in the page before starting the execution of jsp page ? So no matter where include directive is in the jsp code, it will be executed first and content if the included page will be pasted at the top of the page and whatever is the output of the generated servlet code will be attached to this included file content. Is this correct ?

----------------------------------------------------------------------------

<jsp:include page="someJSP.jsp" />

This action directive, whenever encountered in the code, will execute this code and put the content in the original jsp page at the location where this include action is placed.
Does it mean that <jsp:include ...... /> can be placed anywhere in the jsp code ? I have seen this "include" action always at the beginning of the page.

The only difference between action and directive is that directive can be placed anywhere in the code but it will be executed first and its content will always be at the top of the page. It can include only static page. While in case of include action, it can include dynamic pages and its content will be placed at the location where its placed.

Please correct me whereevr I am wrong.





Balu Sadhasivam
Ranch Hand

Joined: Jan 01, 2009
Posts: 874


So no matter where include directive is in the jsp code, it will be executed first and content if the included page will be pasted at the top of the page and whatever is the output of the generated servlet code will be attached to this included file content. Is this correct ?



Nope. Both include directive and jsp:inlcude are position specific.

The difference is include directive makes the jsp to include the content in the translation phase and both ( included jsp and main jsp ) gets compiled after that.
Where as jsp:include includes the data at runtime , when page is being requested. Basically this achieved by kind of RequestDispatcher include() as you do in servlet.
 
wood burning stoves
 
subject: include - directive and action