JSP template inheritance JSP template inheritance django django

JSP template inheritance


You can do similar things using JSP tag files. Create your own page.tag that contains the page structure. Then use a <jsp:body/> tag to insert the contents.


You can use rapid-framework for JSP template inheritance

base.jsp

%@ taglib uri="http://www.rapid-framework.org.cn/rapid" prefix="rapid" %>  <html>      <head>        <rapid:block name="head">            base_head_content        </rapid:block>    </head>      <body>          <br />          <rapid:block name="content">            base_body_content        </rapid:block>      </body>  </html>

child.jsp

<%@ taglib uri="http://www.rapid-framework.org.cn/rapid" prefix="rapid" %>  <rapid:override name="content">       <div>        <h2>Entry one</h2>        <p>This is my first entry.</p>    </div></rapid:override>  <!-- extends from base.jsp or <jsp:include page="base.jsp"> -->  <%@ include file="base.jsp" %> 

output

<html><head>   base_head_content</head>  <body>      <br />      <div>        <h2>Entry one</h2>        <p>This is my first entry.</p>    </div></body>  </html>

source code

http://rapid-framework.googlecode.com/svn/trunk/rapid-framework/src/rapid_framework_common/cn/org/rapid_framework/web/tags/


You'll probably want to look into Tiles.

EDIT: On a related note to tiles, you might want to look into Struts. It's not what you're looking for (that's tiles), but it is useful for someone coming from Django.