• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

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

 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I believe you can include some other jsp pages(not only html pages) to your jsp pages.
 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
------------------
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
Thanks a lot for ur help.
It works.
Subbu
 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic