including an HTML file, within an HTML file, within a JSP file?! 500 points.

hi experts

firstly, apologies for the no doubt very poor description of my problem, i'm playing around with jsp for the very first time, so really don't know what i'm talking about! here goes...

i have an index.html file that includes a header html file, like this:

<!--#include virtual="header.html"-->

the header.html file itself includes another html file, like this:

<!--#include virtual="navbar.html"-->

when i view index.html, everything is fine, and it looks exactly as it should. the problem comes when i then try to do the same on a .jsp page. for example, if i then create index.jsp and include the header file like this:

<jsp:include page="header.html" />

it includes the content of header.html BUT NOT the contents of navbar.html. i can only suspect that it's because i am then using the "#include virtual" method in a jsp page.

so my question is this - without changing navbar.html or header.html (i really need them to stay the same as i use them across all my html files without any problem) how can i include these files in a jsp page?

Who is Participating?
malfunction84Connect With a Mentor Commented:
What you're doing is called "server-side includes" (SSI).  Different servers do them different ways, but it's always the server's responsibility (hence the name).

Tomcat has these directives disabled by default for security reasons.  Instructions for how to enable them can be found here:
have you tried
<%@ include file="header.html">
Why not just convert the HTML files to JSP files?  Then you can use <jsp:include> in header.jsp to include navbar.jsp (or navbar.html for that matter).
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

geordie007Author Commented:


doesn't seem to work.


that's not an option. those files are legacy code that i'm not allowed to change.
Hmm.. strange...

when your jsp page comes.. do a right click--> view source... see how it is rendering...

& also I am assuming that your include HTMLs are in same directory as your jsp..

ideally speaking include page or include file should have worked..

also if you can post the code for these three files, we might be able to see something in the code..
geordie007Author Commented:


when you view the source, you can see the line <!--#include virtual="navbar.html"--> in the served file, so obviously this isn't being processed. it's as though it grabs the content of the header.html file and places it in the jsp 'container' file because it is included as a jsp:include. however, when the header.html file content is grabbed and placed in the jsp file, the next include statement doesn't work because it uses the <!--#include virtual="navbar.html"--> method, and the jsp file doesn't like it.

it really isn't necessary to include the source, as it is a simply a case of:


<jsp:include page="header.html" />


<img src="logo.gif" />
<!--#include virtual="navbar.html"-->



yup..! malfunction is correct..... dunno how I missed that...:-)
geordie007Author Commented:

well, can't say i'm happy, but it's not your fault! :)

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.