MyException.java
package Service;

public class MyException {
	String name;
	String message;
	
	public String execute() throws Exception{
		message="실행중입니다";
		System.out.println("MyException-execute");
		// 일부러 예외를 만들어 보자
		
		int len = name.length(); 
		//java.lang.NullPointerException 발생
		
		message="에러 없이 실행 완료";
		return "success";		
	}

	public String getMessage() {
		return message;
	}
	
}

struts.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd">

	
<struts>
	<constant name="struts.i18n.encoding" value="UTF-8" />
	<constant name="struts.devMode" value="true" />
	
	<package name="hi" extends="struts-default" 
		namespace="/"	>
		
	<!--  예외 발생하면 기본적으로  Exception.jsp 띄우기 -->
	<global-results>
		<result name="error">/Exception.jsp</result>
	</global-results>	
	<global-exception-mappings>
		<exception-mapping result="error" 
		exception="java.lang.Exception"/>
	</global-exception-mappings>
		
	<!--   <result name="error">/Exception.jsp</result>
		   <exception-mapping result="error" 
	     	exception="java.lang.NullPointerException"/>
	-->
	
    
    <action name="Exception"  class="Service.MyException">
    	<result name="error">/Exception.jsp</result>
    	<result>/Exception.jsp</result>
    	<exception-mapping result="error" 
    	exception="java.lang.NullPointerException" />
    </action>
	</package>
</struts>
pageError.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" %>
<%@ page isErrorPage="true"%>
<html>
<body>
<h1>에러 페이지</h1>
${exception}
</body>
</html>

Exception.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>Insert title here</title>
</head>
<body>
	${message }
</body>
</html>





로깅

http://logging.apache.org 

log4j-1.2.15.jar


log4j.properties
# Log4J Settings for log4j 1.2.x (via jakarta-commons-logging)
#
# The five logging levels used by Log are (in order):
#
#   1. DEBUG (the least serious)
#   2. INFO
#   3. WARN
#   4. ERROR
#   5. FATAL (the most serious)

# Set root logger level to WARN and append to stdout
log4j.rootLogger=WARN, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout

# Pattern to output the caller's file name and line number.
log4j.appender.stdout.layout.ConversionPattern=%d %5p (%c:%L) - %m%n

# OpenSymphony Stuff
log4j.logger.com.opensymphony=INFO
log4j.logger.org.apache.struts2=DEBUG

log4j.logger.com.opensymphony.xwork2.util.profiling.UtilTimerStack=INFO





프로파일링


s06.FileIO.zip





+ Recent posts