Customized error pages for Glassfish V3

There are 2 main reason you want to create custom-made error pages to catch 404 (and others).

Default 404 Error Page

  1. It is more professional to catch an error and guide the user either back to a start page or some kind of error handling (appearing as part of you application and not some default Glassfish page which leaves him pretty much nowhere).
  2. You dont reveal any information about the application server and remove the most basic information for any hacker: What server software is running on this host ?

In Glassfish we can make use of 2 levels of error handling. At a global level, for the complete domain, and the application level. The application level error handling overrides the global handling. You can create a 404 error page that leads the user back to the application index and at the global level you create a message that does NOT contain a link to an application (entering a wrong context will show you there is no such application, but dont give you a hint where else to go!)

How to do it ?

Application Level

  • Create a webpage in your web folder (eg. 404.html) with your application design template and add a link to the index page if necessary.
  • Open the web.xml and add
  • or use the assistant in Netbeans

    web.xml in Netbeans

Glassfish Global Level

  • Open you admin console and add a new property
    code=404 path=/tmp/404.html reason=Resource_not_found
    better: code=404 path=${com.sun.aas.instanceRoot}/docroot/404.html reason=Resource_not_found

    Glassfish Console


  • or execute asadmin
    asadmin set”code=404 path=/tmp/404.html reason=Resource_not_found”
  • or do it manually in the domain.xml
     <config name="server-config">
     <access-log />
     <virtual-server id="server" network-listeners="http-listener-2,http-listener-1">
     <property name="send-error_1" value="code=404 path=/tmp/404.html reason=Resource_not_found" />
     <virtual-server id="__asadmin" network-listeners="admin-listener" />
  • Remark: You should place the code=xxx in front the property string (like above sample). There are some forum threads and tutorials putting it at the end (which does not work for me).

9 thoughts on “Customized error pages for Glassfish V3

  1. Hi, I tried application level customization on Glassfish v3, but it is not working. I even tried the assistance of Netbeans but it is still not working. Do you have any other reccommendation? Thanks in advance.

  2. how to set path to css file with stylesheet for 404 page?
    i tried just

    and it searches it in domain:8080/appcontext/css/style.css, not in domain1/docroot/404/ where the error page is

  3. My requirement involves disabling the application during maintenance . When I disable the deployed application in GF and try to access custom error page at application level I end up getting default 404 error rather than the custom 404 page. Please let me know if there are ways to go about this issue.


  4. Hi – this does work for me, but the page being shown is in plaintext, not HTML, even though it’s a properly formatted html file. Any ideas?

  5. Pingback: Hide Glassfish Server Information | The JavaDude Weblog

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