Question:

How to setup error page web xml?

by Guest21431208  |  1 year, 7 month(s) ago

0 LIKES UnLike

I am new to xml, someone please tell me how to setup error page in web xml.

 Tags: Error, page, setup, Web, XML

   Report

1 ANSWERS

  1. James Augustus

    Here are few methods for creating XML error page:
    1. web.xml
    The standard web application configuration file is in <webapp>/WEB-INF/web.xml could be utilize to map errors to specific URLs with the <error-page> element. This element makes a mapping between the error-code or exception type to the location of a resource in the web application.
    • error-code - integrate value
    • exception-type – It is fully qualified class name of a Java Exception type
    • location - location of the resource in web application relative to the root of the web application. Value should start with "/".
    example of Error code:
    <error-page>
    <error-code>404</error-code>
    <location>/jspsnoop/ERROR/404</location>
    </error-page>
    example of Exception:
    <error-page>
    <exception-type>java.io.IOException</exception-type>
    <location>/jspsnoop/IOException</location>
    </error-page>
    2. context file configuration.
    Context files are nomrally found in <jetty.home>/contexts/?.xml (see ContextDeployer for further detail). Context files can be utilized for configuring the default error handler that is required for a context with more flexibility , available with web.xml,
    specifically with the support of error code ranges:
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://jetty.mortbay.org/configure.dtd">

    <Configure class="org.mortbay.jetty.webapp.WebAppContext">
    <Set name="contextPath">/test</Set>
    <Set name="war">
    <SystemProperty name="jetty.home" default="."/>/webapps/test
    </Set>

    <!-- by Code -->
    <Get name="errorHandler">
    <Call name="addErrorPage">
    <Arg type="int">404</Arg>
    <Arg type="String">/jspsnoop/ERROR/404</Arg>
    </Call>
    </Get>

    <!-- by Exception -->
    <Get name="errorHandler">
    <Call name="addErrorPage">
    <Arg>
    <Call class="java.lang.Class" name="forName">
    <Arg type="String">java.io.IOException</Arg>
    </Call>
    </Arg>
    <Arg type="String">/jspsnoop/IOException</Arg>
    </Call>
    </Get>

    <!-- by Code Range -->
    <Get name="errorHandler">
    <Call name="addErrorPage">
    <Arg type="int">500</Arg>
    <Arg type="int">599</Arg>
    <Arg type="String">/dump/errorCodeRangeMapping</Arg>
    </Call>
    </Get>
    </Configure>
     

Question Stats

Latest activity: 1 year ago.
This question has been viewed 298 times and has 1 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.