Error Page Recipe

Serving Tapestry Pages as Servlet Error Pages

Do you want to dress up your site and use a snazzy Tapestry page instead of the default 404 error page? Using modern servlet containers, this is a snap!

Simply upgrade your application web.xml to the 2.4 version, and make a couple of changes:

<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns="" xmlns:xsi=""





Tapestry's filter must be marked as a handler for both standard requests and errors. That's accomplished with the <dispatcher> elements inside the <filter-mapping> section.

You must then map error codes to Tapestry URLs. In this case, the 404 error is send to the /error404 resource, which is really the "Error404" Tapestry page.

We'll create a simple Error404 page, one that displays a message and (in development mode) displays the details about the incoming request.

<html xmlns:t="">

        <title>Resource not found.</title>

        <div class="container">

            <h1>Page or resource not found.</h1>

            <t:if test="! productionMode">
                <t:renderobject object="request"/>


The page simply makes the request and productionMode properties available:
package com.example.newapp.pages;

import org.apache.tapestry5.SymbolConstants;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.apache.tapestry5.ioc.annotations.Symbol;

public class Error404
    private Request request;

    private boolean productionMode;

The end-result, in when not in production mode, looks like this:

An issue with an application that has a root Index page is that any invalid path, which would normally generate a 404 error, is instead routed to the Index page (because the invalid path looks like page's activation context). See Issue TAP5-2070.