• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

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

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 43
Android C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 300
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 67753
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is covered in the JspFaq.
 
Bring me the box labeled "thinking cap" ... and then read this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic