wood burning stoves 2.0*
The moose likes JSP and the fly likes Please explain difference between <%@include..> and <jsp:include>.Thanks in Advance... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Please explain difference between <%@include..> and <jsp:include>.Thanks in Advance..." Watch "Please explain difference between <%@include..> and <jsp:include>.Thanks in Advance..." New topic
Author

Please explain difference between <%@include..> and <jsp:include>.Thanks in Advance...

praneeth gajji
Greenhorn

Joined: Apr 12, 2012
Posts: 24
Can any one please explain difference between thease two along with beloww query.

for example
we have one.jsp having defined String s="1" using scriptlet
two.jsp two.jsp having defined String s="2"
three.jsp with String s="3"

we have included two.jsp into one .jsp with <%@include..> directive
Also we have included three.jsp into one.jsp with <jsp:include..> tag

wheras all jsps have String s defined in it, if we print 's' what will be output,please xplain the reason
sonu raj
Ranch Hand

Joined: Jul 31, 2012
Posts: 43

praneeth gajji wrote:Can any one please explain difference between thease two along with beloww query.

for example
we have one.jsp having defined String s="1" using scriptlet
two.jsp two.jsp having defined String s="2"
three.jsp with String s="3"

we have included two.jsp into one .jsp with <%@include..> directive
Also we have included three.jsp into one.jsp with <jsp:include..> tag

wheras all jsps have String s defined in it, if we print 's' what will be output,please xplain the reason


I think you will get an error because of "Duplicate variable" as two.jsp file is added to one.jsp so the variable 's' also get declared to page one.jsp
and if you just remove String s="1" from one.jsp then the output will be 2.
The output is 2 because of <%@include file="two.jsp"> as the content of this file get included in one.jsp
I think by using <jsp:include...> only output of the file is included.
Correct me if I am wrong
jatan bhavsar
Ranch Hand

Joined: Jul 23, 2008
Posts: 296

Hi,

if you include jsp having variable string s with include in the jsp which has variable string s will give you compilation error, Duplicate variable.

Jsp having variable String s with jsp:include in the jsp which has variable string s wont give error and prints the results.

the Reason is

The include is static content dosent generate at the runtime so i think its giving error for duplicate variable.

While jsp:include is dynamic include which will execute at run time and only response will be added so it doesnt give the error.
Only the response will be the part of jsp so it dosent give the error.

Please correct me if i am wrong.

Regards
Jatan

Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

<%@ include file='' %> :

* executes at translation times .
* you can include static references such as jsp fragments.
* you cant pass parameter to include file
=> so when you include a file(say A.jsp) into another(say B.jsp) ,
then container copies the A.jsp into B.jsp at the time of .java file generation[this is what called as translation time].

so, think of it.

<jsp:include page=''/> :

* executes at run time
* you cant include static references such as jsp fragments.
if you do so. it just process as strings.
*you can pass parameter to include file
=> so it is just as *method call* to another jsp content
so think about it.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60785
    
  65

This is covered in the JspFaq.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Please explain difference between <%@include..> and <jsp:include>.Thanks in Advance...
 
Similar Threads
Cookie Problem
doubt on getProperty in various scopes
I have one.jsp,two.jsp,three.jsp....
previously discussed question
calling different files