SourceForge.net Logo
Version: 0.27 - Last update: 2004-05-30 Home Page - SourceForge Project Page - Contact

Jodd
  Overview
  News
  Download
  License
  References

Development
  Using Jodd
  Javadoc
  JUnit report

Community
  Contribute
  Report a bug

More reading
  Milestone 0.30



Top 25%

BSD
 

JSP templates

The common thing with the JSP is having parts of pages that looks more-less the same on many pages. Jodd JSP templates provides solution for reusing JSP. Templates may be used either as macros or as real templates. Macros usage is similar to usage of m4 unix command. Templates usage is just another way of organizing the JSP source code. All templates and macros are stored in JSP, and all changes will be visible immediately, without restarting the server.

Here is the example of using templates as macros.

Macros
 
<jodd:import page="123.jsp">
	<jodd:param name="inline" value="value1"/>
	<jodd:param name="noval">
		value2
	</jodd:param>
</jodd:import>

Above example inserts (i.e. imports) the specified JSP page (123.jsp) and defines 2 parameters that are used on the imported page. In this example imported page logically serves as a JSP macro that has two parameters.

Here is an example how templates may be used.

Templates usage
 
<jodd:import page="master_template.jsp">
	<jodd:param name="content">
		Content of the page is defined here.<br>
		Code this part as usual.<br>
		Use everything you would use as there were no import tags.
	</jodd:param>
	<jodd:param name="footer" value="verXXX"/>
</jodd:import>

Template is defined in the external file and may looks like this:

Template definition
 
<%@taglib uri="jodd-import" prefix="imp"%>
<html>
<body>
<table border="1" width="80%">
	<tr><td colspan="2">
		header
	</td></tr>
	<tr><td width="20%">
		left side
	</td><td>
		<b>content</b><br>
		<jodd:insert name="content"/>
	</td>
	</tr>
	<tr><td colspan="2">
		<b>footer</b> <jodd:insert name="footer"/>
	</td></tr>
</table>
</body>
</html>

More examples can be found in the distribution archive.


http://jodd.sourceforge.net
najgor at users.sourceforge.net