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:

Layout

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>

<div id=”menu”>

link 1 | link 2 | link 3

</div>

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

FINALLY:

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:

<body>

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

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

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

</body>

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:

<body>

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

<div style=”float:left;”>

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

</div>

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

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

</body>

 

Enjoy working with Java “Master Pages”

Advertisements

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:

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s