Struts2에서 웹표시가 아닌 log에 에러내용을 남기고 싶을때.

Struts.xml 설정
<global-results>
<result name="error">/WEB-INF/web/jsp/error.jsp</result>
</global-results>

<global-exception-mappings>
<exception-mapping exception="java.lang.Exception" result="error"/>
</global-exception-mappings>

error.jsp 내용
<h1>ERROR</h1>
<s:actionerror/>
<p>
<s:property value="%{exception.message}"/>
</p>
<hr/>
<h3>Technical Details</h3>
<p>
<font style="font-size: 9px; color:gray">
<s:property value="%{exceptionStack}"/>
</font>
</p>
...

logfile에 남기기 위해 추가(log4j기준)
<%@page import="org.apache.log4j.Logger"%>
<s:set name="stackTrace" value="%{exceptionStack}" scope="page"/>
<%
String stackTrace = (String) pageContext.getAttribute("stackTrace");
Logger.getLogger(this.getClass()).error(stackTrace);
%>

출처:http://mr678.blogspot.com/2009/03/struts2-unchecked-exceptions-loggen.html

'Struts2' 카테고리의 다른 글

현재 URL 가져오기  (0) 2010.08.14
Struts2 @Results 에서 params이용 방법  (0) 2010.08.12
Validator 날짜 체크 Action  (0) 2010.08.11
validate money check struts2  (0) 2010.08.10
Struts2 validation Byte Check  (0) 2010.08.06

+ Recent posts