Modify the default HTTP error page

The default error page is generated by the Payara Server. Although it's not possible to modify it, it is possible to supply a completely new custom error page for each HTTP error code.
 
You can:
  • specify a custom error page per each application in its web.xml descriptor
  • specify a default error page globally for all applications deployed on a virtual server
It is also possible to mix both options and, in this case, the error page defined in the application will take precedence over the global configuration. In the web.xml, you can use the error-page element to specify your custom page.
 
For global configuration, you would need to modify the virtual server and add a system property named send-error_X (where X is a number, e.g. send-error_1) for every error page you want to override (so that the properties have unique names). The value of the property specifies the error code, path to the html page (ideally relative to the ${com.sun.aas.instanceRoot} variable, and a reason for the error (e.g. "Resource not found"). If you specify more custom error pages (for different error codes), you would choose a different number in the system property name, e.g. send-error_1, send-error_2, etc.
 
An example would be:
 send-error_1=code=404 path=${com.sun.aas.instanceRoot}/docroot/404.html reason=Resource_not_found 
 send-error_2=code=403 path=${com.sun.aas.instanceRoot}/docroot/403.html reason=Forbidden 
 
To add the properties in the Admin Console, navigate to Configurations -> Virtual Servers -> <your virtual server> (where the default virtual server is called "server"):
 
 
To add the properties via the asadmin command, execute the following command (it's necessary to place the value of the properties in quotes when running the command from the command line or system script):
asadmin set server.http-service.virtual-server.server.property.send-error_1=”code=404 path=${com.sun.aas.instanceRoot}/docroot/404.html reason=Resource_not_found”  
asadmin set server.http-service.virtual-server.server.property.send-error_2=”code=403 path=${com.sun.aas.instanceRoot}/docroot/403.html reason=Forbidden” 
For more details, here is an older Stackoverflow question, leading to a more thorough blog post, which describes how to do the configuration in GlassFish 3. The same steps can be applied to Payara Server.
 

Add Comment

Comments

0 comments

Please sign in to leave a comment.

Was this article helpful?
0 out of 0 found this helpful