1

How can I break a single page jsp file into manageable code blocks while keeping all the code in a single file? Equivalent to breaking a class up into methods but keeping it all in one file. For example:

<body>
    <div id="main_container">
        # include header
        # include search form
        # include search results table
        # include footer
    </div>
</body>

# header code ################
<ul id="main_menu">
    <li>home</li>
    .
    .
</ul>

# Search Form Code ################
<form id="search_form">
    <input id="customer_name>
    .
    .
</form>

I want to break the html up into manageable code block to improve readability and make version control easier. I also want to maintain one jsp per page with only common code being moved out into separate jsp files.

KevSheedy
  • 3,195
  • 4
  • 22
  • 26

2 Answers2

1

It looks like you're looking for a templating system like Apache Tiles or Sitemesh.

The alternatives are static JSP includes, dynamic JSP includes, and JSP tag files, which should all be described in you JSP book or tutorial.

JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255
  • Tiles would be the better fit for his description... all code is not kept in one file. But you would not be able to factor out commonality if that were the case and it would defeat the nature of templating but it does allow for the full definition of all templates to be in one place (how everything fits together rather than chase the rabbit down the hole following JSP includes). – Quaternion May 27 '13 at 23:49
0

If you are using JSP you can use include directive and have the chunks in separate JSP files. This also gives you opportunity to reuse parts of the pages, like header, footer, search bar, etc.

Community
  • 1
  • 1
Peter Kofler
  • 9,252
  • 8
  • 51
  • 79