Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8241975
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T21:00:58+00:00 2026-06-07T21:00:58+00:00

Problem: I have two identical pages home.jsp and contact.jsp with same structure. They differs

  • 0

Problem: I have two identical pages home.jsp and contact.jsp with same structure. They differs only in body content and title. I want to create a Layout page using tiles framework and reuse the code for the two JSPs. The controller framework is yet not decided, it may be Spring MVC 3 or Struts 2.

Solution A: Calling JSP files/views directly from controller/action classes.

I write a single definition in tiles.xml like:

<definition name="baseLayout" template="/WEB-INF/jsp/layout/baseLayout.jsp">
    <put-attribute name="title" value="" />
    <put-attribute name="header" value="/WEB-INF/jsp/includes/header.jsp"/>
    <put-attribute name="body" value="" />
</definition>

Now in baseLayout.jsp:

<html>
    <head><title><tiles:insertAttribute name="title"/></title></head>
    <body>
        <div class="wrapper">
            <div class="header"><tiles:insertAttribute name="header"/></div>
            <div class="body"><tiles:insertAttribute name="body"/></div>
        </div>
    </body>
</html>

Now in home.jsp

<tiles:insertDefinition name="baseLayout">
    <tiles:putAttribute name="title">
        Title for home page
    </tiles:putAttribute>
    <tiles:putAttribute name="body">
        Content for home page
    </tiles:putAttribute>
</tiles:insertDefinition>

Similarly for contact.jsp :

<tiles:insertDefinition name="baseLayout">
    <tiles:putAttribute name="title">
        Title for contact page
    </tiles:putAttribute>
    <tiles:putAttribute name="body">
        Content for contact page
    </tiles:putAttribute>
</tiles:insertDefinition>

Solution B: Calling the tiles definition of different JSP files from cotrollers/action classes. This approach requires one tiles definition for each of the JSP file I would be writing. So altogether 3 tiles definitions (one is for baseLayout and other two are for home and contact).

tiles.xml :

<definition name="baseLayout" template="/WEB-INF/jsp/layout/baseLayout.jsp">
    <put-attribute name="title" value="" />
    <put-attribute name="header" value="/WEB-INF/jsp/includes/header.jsp"/>
    <put-attribute name="body" value="" />
</definition>

<definition name="home" extends="baseLayout">
    <put-attribute name="title" value="Title for home page" />
    <put-attribute name="header" value="/WEB-INF/jsp/home.jsp"/>
</definition>
<definition name="contact" extends="baseLayout">
    <put-attribute name="title" value="Title for contact page" />
    <put-attribute name="header" value="/WEB-INF/jsp/contact.jsp"/>
</definition>

baseLayout.jsp : Same as **Solution A**

home.jsp : Content for home page

contact.jsp : Content for contact page


I want advice on which one of the above approaches I should stick to.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T21:00:59+00:00Added an answer on June 7, 2026 at 9:00 pm

    Solution B is the best approach to implement,

    • you will have individual style template what you can reuse later if required for other jsp’s without messing the code in jsp like Solution A.

    • As of understanding the second approach is more clear and a common standard to follow.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two somewhat big (4+ million records) tables with identical structure, and they
I have two pages that are almost identical. However on the second page the
I have two MySQL databases with identical table structure, each populated with several thousand
I have a problem with identical validator of zend framework. I have two elements
I've come here with quite philosophical problem: suppose we have two identical application, with
Here is my problem: I have two dictionaries with identical structures: Dictionary<string, List<Object>> Existing
In this problem, I have three (identically-structured) lists. Two have all numbers and the
Problem: I have two array where one produce a category and the second produce
I have a design problem: I have two threads, a heartbeat/control thread and a
Here is the problem: I have two columns in a table that, for each

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.