Common/ErrorServlet: Difference between revisions
Jump to navigation
Jump to search
imported>Gfis new |
imported>Gfis m Link to Apache Tomcat |
||
| Line 3: | Line 3: | ||
There are several conditions which must be met by the web application: | There are several conditions which must be met by the web application: | ||
* The servlet and all methods called therein must not catch any exceptions themselves, but must - possibly after logging - throw them to the caller. In the end, that will be the container (Tomcat) or application server (WebSphere), which activates the ErrorServlet. | * The servlet and all methods called therein must not catch any exceptions themselves, but must - possibly after logging - throw them to the caller. In the end, that will be the container (Tomcat) or application server (WebSphere), which activates the ErrorServlet. | ||
* The configuration file <code>WEB-INF/web.xml</code> should contain an element for at least the | * The configuration file <code>WEB-INF/web.xml</code> should contain an element for at least the Servlet 3.0 specification (December 2009), which is implemented by [https://en.wikipedia.org/wiki/Apache_Tomcat#Releases Tomcat Version 7] and above. | ||
<nowiki><web-app xmlns="http://java.sun.com/xml/ns/javaee" | <nowiki><web-app xmlns="http://java.sun.com/xml/ns/javaee" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" | xsi:schemaLocation="http://java.sun.com/xml/ns/javaee | ||
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" | |||
version="3.0"> | version="3.0"> | ||
... | ... | ||
</web-app> | </web-app> | ||
</nowiki> | </nowiki> | ||
* <code>web.xml</code> must contain proper references to the <code>ErrorServlet</code> | * <code>web.xml</code> must contain proper references to the <code>ErrorServlet</code>: | ||
<nowiki> | <nowiki> | ||
... | ... | ||
Latest revision as of 13:50, 11 October 2016
ErrorServlet handles Http server error codes (e.g. 404 = file not found), and unexpected internal Java exceptions and shows a corresponding message to the user.
There are several conditions which must be met by the web application:
- The servlet and all methods called therein must not catch any exceptions themselves, but must - possibly after logging - throw them to the caller. In the end, that will be the container (Tomcat) or application server (WebSphere), which activates the ErrorServlet.
- The configuration file
WEB-INF/web.xmlshould contain an element for at least the Servlet 3.0 specification (December 2009), which is implemented by Tomcat Version 7 and above.
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
...
</web-app>
web.xmlmust contain proper references to theErrorServlet:
...
<servlet>
<servlet-name>ErrorServlet</servlet-name>
<servlet-class>org.teherba.common.web.ErrorServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ErrorServlet</servlet-name>
<url-pattern>/ErrorServlet</url-pattern>
</servlet-mapping>
<error-page>
<location>/ErrorServlet</location>
</error-page>
...