Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / October 2005

Tip: Looking for answers? Try searching our database.

Problem with <jsp:include on Tomcat 5

Thread view: 
Grudak@gmail.com - 28 Oct 2005 14:16 GMT
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???
Andrea Desole - 28 Oct 2005 14:57 GMT
> 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.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.