Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSP include action

 
Chris Salivar
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The JSP include action goes something like:
<jsp:include page="test.jsp"/>
while the JSP include directive goes something like:
<%@include file="test.jsp"%>
Whats the significance of the fact that the JSP include action is processed at request time while the JSP include directive at translation time?
TIA
- Chris
 
Tony Alicea
Desperado
Sheriff
Posts: 3226
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
High. The significance is high.
Do you know C? If so, are you familiar with the #include directive?
The include directive in JSPs directs the compiler that's going to compile a JSP, to REPLACE every include directive that it finds with the text contents of the included file. Just like #include in C.
And that's all there is to the include directive. Nothing new there if you know C.
Now to where the (include) action is!
For this you must understand that JSPs are converted literally into source code for servlets first by the JSP engine and then compiled to bytecode just like any other servlet that you may have written by hand.
The file included with the include action is converted to a servlet and compiled into bytecode (if it hadn't been already) and its output (whatever it is) is inserted at the point of inclusion in the enclosing servlet-that-corresponds-to-the-original JSP.
In other words, it's like chaining different servlets together: The first servlet (actually the compiled mother JSP) starts executing, then the servlet engine executes the one that has been included by the include action, then it goes back to the original one and so on.
I know this has not been the best explanation, but "that's what the ship brought for now..."
PS: There are consequences (differences) as to the scope of variables with each type of includes.
 
Chris Salivar
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cool, thanks a lot.
Can you elaborate on the consequences (differences) as to the scope of variables with each type of includes?
TIA
Chris
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic