Hi all, I hope someone can help me understand why this doesn't work. I
guess I don't understand how <jsp:include is supposed to work... :-)
here is include.jsp:
<html>
<body>
<jsp:include page="include.jspf" />
</body>
</html>
and here is include.jspf:
<% String a = "hello"; %>
<%=a%>
when I browse to include.jsp, I would expect to see the word hello in
my browser. However, there is nothing in the browser. when I look at
the source, I see:
<html>
<body>
<% String a = "hello"; %>
<%=a%>
</body>
</html>
what gives??? it seems to be blindly including the jspf file into the
source, rather than *evaluating* the .jsfp file. If I paste the
contents of the .jspf into the .jsp file in place of the <jsp:include
statement, I get the word hello, but that defeats the purpose of code
reuse.
Help???
> Hi all, I hope someone can help me understand why this doesn't work. I
> guess I don't understand how <jsp:include is supposed to work... :-)
You mostly do.
What happens is that jsp:include include the page dynamically, that is
when the page is requested. In this case your included page,
include.jspf, is completely separated from your first page, include.jsp.
Because of this the server has to compile both pages. Now, what I
believe is that your server doesn't know how to compile include.jspf
because of its extension. If you configure Tomcat to compile jspf pages
(you can do that in the web.xml of Tomcat), or if you rename the page to
jsp, it will probably work as expected.
Now, although changing the Tomcat configuration can be a solution, think
about it. What you are using is a jspf, which means "JSP fragment". A
jspf is not meant to be used on its own, at the point that it's usually
put in the WEB-INF directory, where a client can't access it. Because of
this, it doesn't usually make sense to include a jspf dynamically. So,
the possible solutions are probably:
1) rename the jspf to a jsp
2) use the static include, that is, <%@ include ... %>
Grudak@gmail.com - 28 Oct 2005 18:24 GMT
Thanks for the info. Sure enough, just changing the name of the frag
file to .jsp fixed the issue.