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

  • Home
  • SEARCH
  • 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 922147
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T18:58:52+00:00 2026-05-15T18:58:52+00:00

At work I’ve been tasked with turning a bunch of HTML files into a

  • 0

At work I’ve been tasked with turning a bunch of HTML files into a simple JSP project. It’s really all static, no serverside logic to program. I should mention I’m completely new to Java. JSP files seem to make it easy to work with common includes and variables, much like PHP, but I’d like to know a simple way to get something like template inheritance (Django style) or at least be able to have a base.jsp file containing the header and the footer, so I can insert content later.

Ben Lings seems to offer some hope in his answer here:
JSP template inheritance
Can someone explain how to achieve this?

Given that I don’t have much time I think dynamic routing is a little much, so I’m happy to just to have URLs map directly onto .jsp files, but I’m open to suggestion.

Thanks.

edit: I don’t want to use any external libraries, because it would increase the learning curve for myself and others who work on the project, and the company I work for has been contracted to do this.

Another edit: I’m not sure if JSP tags will be useful because my content doesn’t really have any template variables. What I need is a way to be able to do this:

base.html:

<html><body>
{ content.body }
</body></html>

somepage.html

<wrapper:base.html>
<h1>Welcome</h1>
</wrapper>

with the output being:

<html><body>
<h1>Welcome</h1>
</body></html>

I think this would give me enough versatility to do everything I need. It could be achieved with includes but then I would need a top and a bottom include for each wrapper, which is kind of messy.

  • 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-05-15T18:58:53+00:00Added an answer on May 15, 2026 at 6:58 pm

    As skaffman suggested, JSP 2.0 Tag Files are the bee’s knees.

    Let’s take your simple example.

    Put the following in WEB-INF/tags/wrapper.tag

    <%@tag description="Simple Wrapper Tag" pageEncoding="UTF-8"%>
    <html><body>
      <jsp:doBody/>
    </body></html>
    

    Now in your example.jsp page:

    <%@page contentType="text/html" pageEncoding="UTF-8"%>
    <%@taglib prefix="t" tagdir="/WEB-INF/tags" %>
    
    <t:wrapper>
        <h1>Welcome</h1>
    </t:wrapper>
    

    That does exactly what you think it does.


    So, lets expand upon that to something a bit more general.
    WEB-INF/tags/genericpage.tag

    <%@tag description="Overall Page template" pageEncoding="UTF-8"%>
    <%@attribute name="header" fragment="true" %>
    <%@attribute name="footer" fragment="true" %>
    <html>
      <body>
        <div id="pageheader">
          <jsp:invoke fragment="header"/>
        </div>
        <div id="body">
          <jsp:doBody/>
        </div>
        <div id="pagefooter">
          <jsp:invoke fragment="footer"/>
        </div>
      </body>
    </html>
    

    To use this:

    <%@page contentType="text/html" pageEncoding="UTF-8"%>
    <%@taglib prefix="t" tagdir="/WEB-INF/tags" %>
    
    <t:genericpage>
        <jsp:attribute name="header">
          <h1>Welcome</h1>
        </jsp:attribute>
        <jsp:attribute name="footer">
          <p id="copyright">Copyright 1927, Future Bits When There Be Bits Inc.</p>
        </jsp:attribute>
        <jsp:body>
            <p>Hi I'm the heart of the message</p>
        </jsp:body>
    </t:genericpage>
    

    What does that buy you? A lot really, but it gets even better…


    WEB-INF/tags/userpage.tag

    <%@tag description="User Page template" pageEncoding="UTF-8"%>
    <%@taglib prefix="t" tagdir="/WEB-INF/tags" %>
    <%@attribute name="userName" required="true"%>
    
    <t:genericpage>
        <jsp:attribute name="header">
          <h1>Welcome ${userName}</h1>
        </jsp:attribute>
        <jsp:attribute name="footer">
          <p id="copyright">Copyright 1927, Future Bits When There Be Bits Inc.</p>
        </jsp:attribute>
        <jsp:body>
            <jsp:doBody/>
        </jsp:body>
    </t:genericpage>
    

    To use this:
    (assume we have a user variable in the request)

    <%@page contentType="text/html" pageEncoding="UTF-8"%>
    <%@taglib prefix="t" tagdir="/WEB-INF/tags" %>
    
    <t:userpage userName="${user.fullName}">
      <p>
        First Name: ${user.firstName} <br/>
        Last Name: ${user.lastName} <br/>
        Phone: ${user.phone}<br/>
      </p>
    </t:userpage>
    

    But it turns you like to use that user detail block in other places. So, we’ll refactor it.
    WEB-INF/tags/userdetail.tag

    <%@tag description="User Page template" pageEncoding="UTF-8"%>
    <%@tag import="com.example.User" %>
    <%@attribute name="user" required="true" type="com.example.User"%>
    
    First Name: ${user.firstName} <br/>
    Last Name: ${user.lastName} <br/>
    Phone: ${user.phone}<br/>
    

    Now the previous example becomes:

    <%@page contentType="text/html" pageEncoding="UTF-8"%>
    <%@taglib prefix="t" tagdir="/WEB-INF/tags" %>
    
    <t:userpage userName="${user.fullName}">
      <p>
        <t:userdetail user="${user}"/>
      </p>
    </t:userpage>
    

    The beauty of JSP Tag files is that it lets you basically tag generic markup and then refactor it to your heart’s content.

    JSP Tag Files have pretty much usurped things like Tiles etc., at least for me. I find them much easier to use as the only structure is what you give it, nothing preconceived. Plus you can use JSP tag files for other things (like the user detail fragment above).

    Here’s an example that is similar to DisplayTag that I’ve done, but this is all done with Tag Files (and the Stripes framework, that’s the s: tags..). This results in a table of rows, alternating colors, page navigation, etc:

    <t:table items="${actionBean.customerList}" var="obj" css_class="display">
      <t:col css_class="checkboxcol">
        <s:checkbox name="customerIds" value="${obj.customerId}"
                    onclick="handleCheckboxRangeSelection(this, event);"/>
      </t:col>
      <t:col name="customerId" title="ID"/>
      <t:col name="firstName" title="First Name"/>
      <t:col name="lastName" title="Last Name"/>
      <t:col>
        <s:link href="/Customer.action" event="preEdit">
          Edit
          <s:param name="customer.customerId" value="${obj.customerId}"/>
          <s:param name="page" value="${actionBean.page}"/>
        </s:link>
      </t:col>
    </t:table>
    

    Of course the tags work with the JSTL tags (like c:if, etc.). The only thing you can’t do within the body of a tag file tag is add Java scriptlet code, but this isn’t as much of a limitation as you might think. If I need scriptlet stuff, I just put the logic in to a tag and drop the tag in. Easy.

    So, tag files can be pretty much whatever you want them to be. At the most basic level, it’s simple cut and paste refactoring. Grab a chunk of layout, cut it out, do some simple parameterization, and replace it with a tag invocation.

    At a higher level, you can do sophisticated things like this table tag I have here.

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

Sidebar

Related Questions

At work we are being asked to create XML files to pass data to
I work on a multi culture web project. I use Localize and Global Ressources(resx)
I work on the same project on two different computers, desktop and laptop .
At work we are currently still using JUnit 3 to run our tests. We
I work in VBA, and want to parse a string eg <PointN xsi:type='typens:PointN' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
I work with C# at work but dislike how with webforms it spews out
At work, we have multiple branches that we may be working on at any
I work on a complex application where different teams work on their own modules
I work for a .NET/MSSQL shop that has trouble supporting customers running Novell, partially
I work a lot with network and serial communications software, so it is often

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.