• Post Reply Bookmark Topic Watch Topic
  • New Topic

Jsp include directive and include jsp action differences

 
swathi kuchibhotla
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I read the differences between <%@ include file > and jsp:include page="" ; but i find it difficult to understand.

I have three jsp pages task1.jsp , task2.jsp, task3.jsp

if i had included task1.jsp inside task3.jsp using directive in the below way,

<%@ include file = "task1.jsp">

And if i had changed the contents of task1.jsp and then compile task3.jsp ( in which task1.jsp is included )

will the changed contents of the task1.jsp be displayed ??

if that is the case what is the actual difference between jsp:include ; <%@include >


Thanks,



 
Vishwanathan Nagarajan
Ranch Hand
Posts: 37
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

@ directive include is static include, when the content in task1.jsp is static then you can include that inside task3.jsp using @ include.

In this case if task1.jsp has changed in the runtime, it will not reflect in task3.jsp.

In the case of jsp action include (jsp:include), it is a dynamic include; in this case if task1.jsp has changed in the runtime, it will reflect in task3.jsp.

So for the common pages which are used accross all pages, like the header, menu bars etc., should be included using jsp:include so that whenever changes happen to these common pages, it gets reflected across all pages during runtime.




 
dileep keely
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In case of directive tag, the task1 and task3 are merged(contents) and a single servlet is generated,hence no need to be a standalone.
In case of action, the pages get executed separately as a servlet and should be able to standalone.Here only the ouput is merged.
 
venkatesh goud
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Think of the include directive as a header file of languages like C/C++. When using the include directive, the combined contents of the original JSP page and all its included resources are translated into the same implementation servlet i.e. the contents of the included resource is copy pasted before translation to a servlet. The important thing here is that all this happens during translation time and only static content is supported.

The include action <jsp:include> is almost similar to the include directive except for a few subtle differences. The include action is executed at request time as opposed to translation time. Thus instead of the content of the include file being included in the calling JSP, the output of the JSP is included or passed to the JSPWriter of the calling page. This allows us to include both static and dynamic content into the JSP page. Using the jsp action also allows you to explicitly pass parameters to the included page.
JSP Syntax (Toggle Plain Text)

1.
<jsp:include page="/index.jsp">
2.
<jsp:param name="name" value="sos" />
3.
</jsp:include>
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!