<servlet> <servlet-name>dispatcherServlet</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:spring/spring-config.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <error-page> <error-code>404</error-code> <!--<location>/error/404code.jsp</location>--> <location>/WEB-INF/view/exception/throwable.jsp</location> </error-page> <error-page> <exception-type>java.lang.Throwable</exception-type> <location>/error/404code</location> </error-page>
■ spring-config.xml
<import resource="exception-config.xml" /> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <!-- Example: a logical view name of 'showMessage' is mapped to '/WEB-INF/jsp/showMessage.jsp' --> <property name="prefix" value="/WEB-INF/view/"/> <property name="suffix" value=".jsp"/> </bean>
■ exception-config.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:p="http://www.springframework.org/schema/p" xmlns:util="http://www.springframework.org/schema/util" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd "> <bean class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver"> <property name="exceptionMappings"> <props> <prop key="java.lang.Exception">exception/defaultException</prop> <prop key="RuntimeException">exception/runtimeException</prop> <prop key="java.sql.SQLException">exception/sqlException</prop> </props> </property> </bean> </beans>
■ HelloController.java
@RequestMapping(value="/hello") public class HelloController { private static final Logger log = LoggerFactory.getLogger(HelloController.class); @RequestMapping(value="/list") public String list ( HttpServletRequest request, ModelMap model) throws Exception { return "/hello/list"; } @RequestMapping(value="/list2") public String list2 ( HttpServletRequest request, ModelMap model) throws Exception { throw new Exception(); } @RequestMapping(value="/list3") public String list3 ( HttpServletRequest request, ModelMap model) throws Exception { throw new SQLException(); } @RequestMapping(value="/list4") public String list4 ( HttpServletRequest request, ModelMap model) throws Exception { throw new RuntimeException(); } }
- SpringBoot Port 변경 2022년 12월 27일
- Spring 트랜잭션 관리 2019년 6월 20일
- Spring RESTful 웹 서비스 사용하기 2019년 6월 19일
- Spring RESTful 웹 서비스 2019년 6월 19일
- Spring Scheduling Task 예제 2019년 6월 18일
- spring mybatis mysql 연결 예제 2018년 5월 4일
- Spring Path Parameter 예제 2018년 2월 13일
- AngularJS $http, spring TEXT response 예제 2018년 1월 17일
- jdom2를 이용한 spring xml response(응답) 2017년 12월 5일
- jquery xml 요청, spring xml 리턴 2017년 12월 5일
- spring controller에서 get, post 동시 허용 방법 2017년 12월 5일
- mybatis, oracle procedure(오라클 커서)를 통한 데이터 조회 2017년 11월 6일
- HTTP 406 Not Acceptable in Spring, Jackson, Json 2017년 11월 6일
- ServletContextLister를 구현한 웹 애플리케이션 시작 시 작업 2016년 5월 2일
- Web Application MessageResource 2016년 3월 8일
- org.mariadb.jdbc.internal.common.QueryException : No database selected 2016년 2월 19일
- jquery spring – checkbox로 선택된 배열 주고 받기 2015년 8월 15일
- jquery spring ajax call 2015년 8월 15일
- spring json return 2015년 8월 15일
- spring exception – SimpleMappingExceptionResolver 2015년 8월 8일