This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JSP and the fly likes Header & Footer with JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Header & Footer with JSP" Watch "Header & Footer with JSP" New topic

Header & Footer with JSP

Moses Babylone

Joined: Aug 01, 2013
Posts: 3
I am a newbie for JAVA and jsp.
I have a fix code for header and for footer which I want to use for all my pages. I don't want to duplicate it. In PHP, we can do this by creating a file header.php and footer.php and including these files whenever required.
I am wondering how I can do the same with jsp? I want to create header and footer and include them in the pages. I don't want to create a template though. Not all pages use same header and footer. So, I must have a flexibility to choose where I could include these 2 files or not.

d v lokesh venkata

Joined: Aug 09, 2013
Posts: 16

you can achieve the same in jsp by using <jsp:include> tag or <%@include --->
save the header part in header.jsp and footer part in footer.jsp
do the following
<%@include file="header.jsp">
/////////////////your code//////////////
/////////////////your code//////////////
/////////////////your code//////////////
<%@include file="footer.jsp">
K. Tsang

Joined: Sep 13, 2007
Posts: 2229

Do note that <jsp:include page=...> is for dynamic content and <%@include file=...> is for static content.

d v lokesh venkata

Joined: Aug 09, 2013
Posts: 16

when you are going with using of css templates you can go with <%@include----
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 60740

d v lokesh venkata wrote:when you are going with using of css templates you can go with <%@include----

Which type of include is used in irrelevant with respect to using CSS on the page or not.

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
wood burning stoves
subject: Header & Footer with JSP
Similar Threads
Design choice for dispatching request to view
Getting include to work
Difference Between jsp include directive and include action element.
sharing tiles / definitions across applications
How to add HTML tags to Response Servlet