How to change Glassfish's default error page?
I'm writing Grails application, tha开发者_开发问答t sometimes responds with 422 http status code (on invalid AJAX calls). While deployed on Glassfish, container includes default error page after my view's rendered text.
How to change this behaviour?
Regards, Tarmo
If you want to change it for the complete domain (the solution below only works for the specific application context) you need to adjust domain.xml.
...
<config name="server-config">
<http-service>
<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>
<virtual-server id="__asadmin" network-listeners="admin-listener" />
</http-service>
...
(as How to change default error page(status 404 - not found) in GlassFish 3.0.1 Community Edition?)
Adding an <error-page>
element in your web.xml should work:
<error-page>
<error-code>422</error-code>
<location>location_of_your_custom_error_page</location>
</error-page>
To do so, run:
grails install-templates
Edit
src/templates/artifacts/war/web.xml
From within your Grails application you can configure the error code mappings by creating a Response Code URL Mapping in grails-app/conf/UrlMappings.groovy
. This URL mapping can let you map a status code to an error page specific to that code.
class UrlMappings {
static mappings = {
"422"(controller:"errors", action:"my422Error")
...
}
}
精彩评论