aspose file tools*
The moose likes Servlets and the fly likes How to include a part of html code in to a jsp page? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to include a part of html code in to a jsp page?" Watch "How to include a part of html code in to a jsp page?" New topic
Author

How to include a part of html code in to a jsp page?

Subbu Aswathanarayan
Ranch Hand

Joined: Jun 22, 2001
Posts: 73
Hi,
I have a peculiar problem.In my web app there are around 4to 5 jsp pages and i want all these pages to share a common border on the top and left, while the other contents of the page will vary.how can i achive this.i am aware abt the include directive of jsp, but i think it can be used to include only complete html file and not part of the code.to be more precise, i want to include half of the final code from some other page while i want to generate the rest of the code dynamically.
how can i do this?
Subbu


Subbu
ken chou
Ranch Hand

Joined: Feb 08, 2001
Posts: 68

I believe you can include some other jsp pages(not only html pages) to your jsp pages.
Robert Brunner
Ranch Hand

Joined: Jul 18, 2001
Posts: 49
I would suggest you do some code refactoring and then include the refactored code snippets wherever you need them. A more elegant technique might be to turn each snippet into a JavaBean, and then *use* them where you need them.
Bart Tubalinal
Greenhorn

Joined: Jul 18, 2001
Posts: 7
Originally posted by Subbu Aswathanarayan:
Hi,
I have a peculiar problem.In my web app there are around 4to 5 jsp pages and i want all these pages to share a common border on the top and left, while the other contents of the page will vary.how can i achive this.i am aware abt the include directive of jsp, but i think it can be used to include only complete html file and not part of the code.to be more precise, i want to include half of the final code from some other page while i want to generate the rest of the code dynamically.
how can i do this?
Subbu

I did something similar to this. If the first file is called "top.jsp" and the second file is called "left.jsp" you can code it like this (or something similar):
<!-- index.jsp file -->
<html>
<head>
<title></title>
</head>
<body>
<table width="100%">
<tr>
<td colspan="2">
<jsp:include page="top.jsp" flush="true" />
</td>
</tr>
<tr>
<td>
<jsp:include page="left.jsp" flush="true" />
</td>
<td>
<% String filename = request.getParameter("file"); %>
<jsp:include page="<%= filename %>" flush="true" />
</td>
</tr>
</table>
</html>
Of course, this can be modified in any way. In fact, in your "top.jsp" file, you can put everything contained in this file (index.jsp) up until the include action for the top.jsp.
so top.jsp can be:
... some jsp/html code ..
<html>
<head>
<title></title>
</head>
<body>
<table width="100%">
<tr>
<td colspan="2">
------------------
and index.jsp can just be:
<jsp:include page="top.jsp" flush="true">
</td>
</tr>
</table>
... and the rest ...
I hope this helped.
Rodrigo de la Parra
Greenhorn

Joined: Jul 18, 2001
Posts: 1
I'm currently developing an e-commerce site for a big client that requires to handle multiple audiences and each one has a different header and navigation but they share the same functionality so what we do is to use the include JSP tag and we load the audience specific HTML pieces using the information provided in the session. The files are just plain text with .inc extensions and HTML code inside and it works pretty nice given that we have like 40 audiences and 100 include files for each one.
Tom Ebert
Greenhorn

Joined: Jul 18, 2001
Posts: 3
Hi Subbu,
the <%@ include file="somePieceOfCode.html" %> directive does not care for the somePieceOfCode.html-file to be some complete html-file. Both files will be merged at compilation time into one servlet.
------------------
Robin Kimzey
Greenhorn

Joined: Jul 19, 2001
Posts: 4
Subbu,
No, you do NOT have to include a complete HTML file when using the #INCLUDE functionality in .JSP pages. It is a direct copy of the included file contents into your JSP page.
Enjoy,
Robin
Subbu Aswathanarayan
Ranch Hand

Joined: Jun 22, 2001
Posts: 73
Hi all,
Thanks a lot for ur help.
It works.
Subbu
 
wood burning stoves
 
subject: How to include a part of html code in to a jsp page?
 
Similar Threads
page directive
applet path
applet servlet communication
Jsp to HTML
Store jsp content in database