Define exception page in spring MVC-Define Exception Problem handling page

Source: Internet
Author: User
Tags define exception

The first method, defined in Spring-servlet.xml
<?xml version= "1.0"  encoding= "UTF-8"? ><beans  xmlns= "http// Www.springframework.org/schema/beans " xmlns:xsi=" Http://www.w3.org/2001/XMLSchema-instance "xmlns:mvc=" Http://www.springframework.org/schema/mvc " xmlns:context=" Http://www.springframework.org/schema/context " xmlns:aop= "HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP"  xmlns:tx= "Http://www.springframework.org/schema/tx"  xsi:schemalocation= "Http://www.springframework.org/schema/mvc http://www.springframework.org/schema /mvc/spring-mvc.xsdhttp://www.springframework.org/schema/beans http://www.springframework.org/schema/ Beans/spring-beans.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema /context/spring-context.xsd        http://www.springframework.org/ schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd          http://www.springframewOrk.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd "><!--  Dispatcherservlet context: defines this servlet ' s request-processing  infrastructure --><!--Notes driver  Enables the Spring MVC  @Controller   programming model --><mvc:annotation-driven>  <!--<mvc:argument-resolvers >            <bean class= " Org.springframework.mobile.device.DeviceWebArgumentResolver " />       </mvc:argument-resolvers>--></mvc:annotation-driven><!--  Scanners  -->     <context:component-scan base-package= "Me"  /> <mvc:resources mapping= " /shakearoud.html " location="/shakearoud.html " />       <!-- -Configure interceptors not to intercept static resources  <mvc:resources mapping= "/img/**" location= "/img/"  />   <mvc:resources mapping= "/fonts/**"  location= "/ fonts/" />      <mvc:resources mapping="/js/** " location="/ js/" />       <mvc:resources mapping="/css/** "  location= "/css/"  />--> <!--add spring mvc intercepters    < Mvc:interceptors>    <bean class= " Org.springframework.web.servlet.i18n.LocaleChangeInterceptor " /> <mvc:interceptor>     <mvc:mapping path= "/"/>        <bean  class= "Me.chanjar.weixin.cp.Interceptor.MyHandlerInterceptor" >        <property name= "Openingtime"  value= "/>       "     <property name= "Closingtime"  value= "26"/>        </bean> </mvc:interceptor>     </mvc:interceptors>-->     <mvc:interceptors>     <bean class= "Org.springframework.mobile.device.DeviceResolverHandlerInterceptor"  / >        <bean class= " Me.chanjar.weixin.cp.Interceptor.MyHandlerInterceptor ">   <property name=" Openingtime " value=" 1 "/>           <property  name= "Closingtime"  value= "/></bean>     </mvc:interceptors" > <!---Configuring interceptors--><!--  Configure view resolver. resolves views selected for rendering by  @Controllers  to .jsp  Resources in the /web-inf/views directory --><bean class= " Org.springframework.web.servlet.vIew. Internalresourceviewresolver "><!--  prefix  --><property name=" prefix " value="/"  /><!--  suffix  --><property name= "suffix"  value= ". JSP"  /></bean ><!--the required &nbsp for  spring multipart file upload, to check if the request contains Multipart      see: http ://www.html.org.cn/books/springreference/ch13s08.html      -->       <bean id= "Multipartresolver"  class= " Org.springframework.web.multipart.commons.CommonsMultipartResolver ">     </bean > <!--Defining exception Handling page-->    <bean id= "Exceptionresolver"  class= " Org.springframework.web.servlet.handler.SimpleMappingExceptionResolver ">         <property name= "Exceptionmappings" >             <props>    &Nbsp;           <prop key= " Org.springframework.web.HttpSessionRequiredException ">Error</prop>                 <prop key= "Java.io.IOException" > Outexception</prop>            </props >        </property>    </bean>< Import resource= "Classpath:applicationContext.xml"/></beans>
The second method, Web. XML, defines the processing page

I know that there are two ways to configure Error-page in Web. XML, one is to configure by error code, but to configure it by the type of exception, respectively, as follows:

A. Configuring Error-page with error codes

Eg.

<error-page> <error-code>500</error-code> <location>/error.jsp</location> & Lt;/error-page>

The above is configured to jump to the error handling page error.jsp when the system has a 500 error (that is, a server internal error).

two. Configuring Error-page by type of exception

Eg.

<error-page> <exception-type>java.lang.NullException</exception-type> <location>/e Rror.jsp</location> </error-page>

configured above when the system occurs java.lang.NullException (i.e. null pointer exception), jump to error handling page error.jsp


Define exception page in spring MVC-Define Exception Problem handling page

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.