Base Layout JSP with insertAttribute

Harry · 23 Sep 2026 · 1 views
Log in to track your progress and mark lessons complete.

layout.jsp

<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles" %>
<html><head><title><tiles:getAsString name="title"/></title></head>
<body>
  <header><tiles:insertAttribute name="header"/></header>
  <nav><tiles:insertAttribute name="menu"/></nav>
  <main><tiles:insertAttribute name="body"/></main>
  <footer><tiles:insertAttribute name="footer"/></footer>
</body></html>

insertAttribute vs getAsString

  • insertAttribute - renders the attribute (JSP include or nested definition).
  • getAsString - prints a string attribute (page titles).
  • useAttribute - exposes it as a scripting variable for logic.

Missing Attributes

Set ignore="true" on optional inserts (sidebars only some pages have) so absent attributes render nothing instead of erroring.

Key Points

  • Layout JSPs contain zero business content.
  • Match every insertAttribute name with a put-attribute.
  • Optional regions need ignore=true.
Share this post:

Comments (0)

Please login or register to comment.

Create a free account to keep reading

You've enjoyed a free tutorial! Register (it's free) to unlock every tutorial, track your progress and save code.

or sign in with your account

Already have an account? Log in