Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
praneeth gajji
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 43
Android C++ Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 299
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<%@ 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
Pie
Posts: 64827
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is covered in the JspFaq.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic