Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

This tutorial teaches you how to setup set up SiteMesh within a web application Java Web Development Environment and should take about 5 minutes or less.

Tip

Shortcut: Don't have a development environment handy or know how to set one up? Download the SM Starter Package which contains SiteMesh with all the exmaples in a pre-configured development environment. Best of all, no install necessary, just unzip and run"no install" SiteMesh Starter Kit which complets the steps below and skip straight to Start Using SiteMesh in 10 Minutes.

Setup Web Application

Setup your web application with your favourite JEE IDE such as Eclipse or the Spring Tool Suite.

If you are new to JEE development and plan to follow along with the Start Using SiteMesh in 10 Minutes tutorial, use the context root of cafe.

Install SiteMesh Manually

...

Code Block
languagexml
<filter>
	  <filter-name>sitemesh</filter-name>
	  <filter-class>com.opensymphony.sitemesh.webapp.SiteMeshFilter</filter-class>
</filter>

<filter-mapping>
	  <filter-name>sitemesh</filter-name>
	  <url-pattern>/*</url-pattern>
</filter-mapping>

Here is a sample web.xml,

Code Block
titleSample web.xml
languagexml
collapsetrue
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">

  <display-name>mirabeau</display-name>

  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>

  <filter>
    <filter-name>sitemesh</filter-name>
    <filter-class>com.opensymphony.sitemesh.webapp.SiteMeshFilter</filter-class>
  </filter>

  <filter-mapping>
    <filter-name>sitemesh</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>

</web-app>

Add Decorator Controller File

Create the a decorators.xml file in your WEB-INF directory,

Code Block
titledecorators.xml
languagexml
<?xml version="1.0" encoding="UTF-8"?>
<decorators>
</decorators>
Note

You IDE (Integrated Development Environment) may give you the warning, "No grammar constraints (DTD or XML schema) detected for the document."

This is just a warning (happens with many other xml files) and you can ignore it or disable the warning in your IDE.

If you start up your application server (container) and get no errors then SiteMesh is is ready to go. However, SiteMesh will not do anything yet. Continue to Start Using SiteMesh in 10 minutesMinutes.