?
Solved

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

Posted on 2007-10-04
8
Medium Priority
?
220 Views
Last Modified: 2013-11-23
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?

thanks
0
Comment
Question by:geordie007
  • 3
  • 3
  • 2
8 Comments
 
LVL 19

Expert Comment

by:Kuldeepchaturvedi
ID: 20015701
have you tried
<%@ include file="header.html">
0
 
LVL 8

Expert Comment

by:malfunction84
ID: 20016199
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).
0
 
LVL 7

Author Comment

by:geordie007
ID: 20020527

@Kuldeepchaturvedi:

doesn't seem to work.

@malfunction84:

that's not an option. those files are legacy code that i'm not allowed to change.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 19

Expert Comment

by:Kuldeepchaturvedi
ID: 20020964
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..
0
 
LVL 7

Author Comment

by:geordie007
ID: 20021045

@Kuldeepchaturvedi

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:

index.jsp:

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

header.html:

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

navbar.html:

<ul>
<li>home</li>
</ul>

thanks
0
 
LVL 8

Accepted Solution

by:
malfunction84 earned 2000 total points
ID: 20021367
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:
http://tomcat.apache.org/tomcat-5.5-doc/ssi-howto.html#installation
0
 
LVL 19

Expert Comment

by:Kuldeepchaturvedi
ID: 20021870
yup..! malfunction is correct..... dunno how I missed that...:-)
0
 
LVL 7

Author Comment

by:geordie007
ID: 20022117

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

thanks
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Suggested Courses
Course of the Month17 days, 6 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question