note

struts2 예외발생 에러페이지 본문

JSP/Struts2

struts2 예외발생 에러페이지

투한 2012. 2. 22. 17:36





struts.xml
<!-- 에러페이지 설정하기-->
		<action name="exceptionThrowing" class="com.ch6.action.ExceptionThrowingAction">
			<result name="success">success.jsp</result>
			<result name="error">error.jsp</result>
			<exception-mapping result="error" exception="java.lang.Exception" />
		</action>


ExceptionThrowingAction.java
package com.ch6.action;

import com.opensymphony.xwork2.Action;

public class ExceptionThrowingAction implements Action{

	@Override
	public String execute() throws Exception {
		if(true)
			throw new Exception("Action Exception occured");
		return SUCCESS;
	}

}



error.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>error</title>
</head>
<body>
${exception}
</body>
</html>