Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jsp:include vs. the include directive

 
stephen dimitrov
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • 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
 
Serghei Jelauc
Ranch Hand
Posts: 128
  • Mark post as helpful
  • send pies
  • 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.
 
Bhumika Thakkar
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • 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.
 
Narendra Dhande
Ranch Hand
Posts: 951
  • Mark post as helpful
  • send pies
  • 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
 
Vishwa Kumba
Ranch Hand
Posts: 1066
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic