• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

jsp:include vs. the include directive

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Consider the contents of 2 JSP files:
File : test.jsp
<html>
<body>
<% String s = "Hello"; %>
//1 insert LOC here.
<%=s%>
</body>
</html>

File : test2.jsp
<% s = s+" world"; %>

According to what I've read, inserting '<jsp:include page="test2.jsp"/>' at //1 causes an error, since s isn't defined in test2.jsp. My questions:

- Is this true?
- If so, does that mean anything included with jsp:include must be a complete JSP (i.e., start and end with <head><body> ?
- Does this mean a file imported with c:import must also be a 'complete' JSP?

Thanks,
Stephen
 
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes it is true. Using <jsp:inlude> standard action each jsp file will be compiled and executes separately and only after it the output (not content) of the page2.jsp will be included into the page1.jsp.
Using <%@ include> directive the content of the page2.jsp will be included into the page1.jsp and only after it, page1.jsp will be compiled (for a first request) and executed.
 
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should NOT add html start/end tags in your included jsp page.

The included jsp page won't have access to the local variables of the caller page. If you want to access a variable that is defined in the caller put it in attributes or params.
 
Ranch Hand
Posts: 951
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Including start/ end HTML tag does not change the JSP execution. Most of the boroser display properly such content. But it is good practice not to incluse such a tags in included HTML. Some browsers/ application thtat validate the HTML may not take such HTML codes.

Thanks
 
Ranch Hand
Posts: 1066
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Narendra Dhande:
Hi,

Including start/ end HTML tag does not change the JSP execution. Most of the boroser display properly such content. But it is good practice not to incluse such a tags in included HTML. Some browsers/ application thtat validate the HTML may not take such HTML codes.

Thanks



I think IE 6.0 works OK with multiple HTML start/end tags, but not sure about Netscape and FireFox.

Coming to the difference, the include directive is an inclusion at compile time(page translation time) and the action include is inclusion at run time.
 
Popeye has his spinach. I have this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic