Using “Master Pages” in JAVA

Java "Master Pages"

As all may know, one of the main disadvantage of Java over C# programming using Visual Studio, is the use of Master Pages. Master Pages allow any developer to create the desired layout of the site. Any page created given that master page will inherit that same design and simply add the content to it. Now, in JAVA this is not possible. This brings along the redundant amount of data replicated on each page within a website. It is very time consuming since a change in design requires a change in all pages.

A tool very useful which may be the closest thing to Master Pages, is the use of Includes in JSP pages. The Include tag allows any page to be inserted into a page. Therefore lets say we would like to create this page:


Steps in Using Includes Tags:

Create New JSP page and Name Header.jsp

In the header jsp you may include all the divs and styles (logo, text, etc) without any <html> starting or closing tags. So, the header.jsp content should look like this:

<div id=”header”>

Logo | some text here


<div id=”menu”>

link 1 | link 2 | link 3


Another Page may be created for the footer and be named footer.jsp containing the <div> or content it may require.


Create the actual index page and put all together. This is done by writing the includes tag wherever you need the pages to be shown. Between the <body> tags in this case we shall include the header and footer by:


<jsp:include page=”header.jsp”/>

<div> Content Here Depending on Page </div>

<jsp:include page=”footer.jsp”/>


Any References or java script may also be included between the <head> tags.


P.S In the event you would like a LeftPane.jsp the main page would look like:


<jsp:include page=”header.jsp”/>

<div style=”float:left;”>

<jsp:include page=”LeftPane.jsp”/>


<div style=”float:right;”> Content Here Depending on Page </div>

<jsp:include page=”footer.jsp”/>



Enjoy working with Java “Master Pages”

11 thoughts on “Using “Master Pages” in JAVA

  1. Pingback: Implement “Master Pages” in Java « Clive Ciappara | Windows | iPhone | .Net

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s