GlassFish v2.1.1 & Custom Error Messages

There are times when you might want to enable custom exotic jazzy error messages instead of the boring 404 or 500 messages. It can be due to various reasons. Security, to avoid scarring the users, etc.,

You can enable custom error messages either server wide (all applications in a server) or only to a specific application in the server.

To enable it across all applications :

This is specific to Glassfish v2.1.1, for the other versions it may vary.

Method 1:  editing the domain.xml manually.

  1. goto glassfish\domains\{domain directory}\config\domain.xml
  2. copy the custom error message html files here.
  3. Open the domain.xml file located in the same folder.
  4. Find the tag “virtual-server”, which has an attribute “id” with the value “server”
  5. Add a sub element to that virtual-server element like this.

<property name=”send-error_1″ value=”code=404 path=404.html”/>

the name attribute value has to be of the format send-error_n where n is a number. for different errors increase the value of n and change the value of value attribute.    The value has two parts code and path.    code is the three digit HTTP response code, eg: 400, 404, 500, 502 etc..    the value of path is the path to the custom error html page. this path is relative to the position of this domain.xml.

Method 2:  Via Admin Console.

  1. login to Administration Console.
  2. In the tasks menu on the left, goto Configuration => HTTP Service => Virtual Servers => server
  3. In the right pane, scroll down to the bottom, and click on the Add Property button.
  4. under name enter “send-error_1”, and under value enter “code=404 path=404.html”
  5. similarly for every error add a property and enter the values, for explanation on values for name and value refer to Method 1.

To enable it to a specific deployed application :

Custom error messages can be enabled for a particular deployed application, by modifying the deployment descriptor file. In web.xml file, under the web-app element add the following,


You can add multiple error-page element for each error. the location, is the path to the custom error page.   The path is relative to the docroot of the application.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s