좋아, 나는이 JSP 작업에 익숙해 져있다. 그러니 올바른 방법이 아니면 내게 십자가에 못 박는 다.JSP 스택 스택 인쇄
오류가 발생한 예외뿐만 아니라 모든 원인 체인에 대해 stackTrace를 error.jsp 페이지에 인쇄해야합니다. 그래서, 난 내 web.xml 파일이 퍼팅에 의해 시작 : 다음
<error-page>
<exception-type>java.lang.Throwable</exception-type>
<location>/error.jsp</location>
</error-page>
, 나는이 error.jsp 파일을 작성했습니다 :
그것은 제대로 작동하고 꽤 잘 일을하고 있어요<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page isErrorPage="true" %>
<%@ page import="java.lang.Throwable" %>
<%@ page import="java.lang.StackTraceElement" %>
<html>
<head>
<title>An Error!</title>
</head>
<body>
<h1>An Error!</h1>
<table width="100%" border="1">
<tr valign="top">
<td width="40%"><b>Error:</b></td>
<td>${pageContext.exception}</td>
</tr>
<tr valign="top">
<td><b>URI:</b></td>
<td>${pageContext.errorData.requestURI}</td>
</tr>
<tr valign="top">
<td><b>Status code:</b></td>
<td>${pageContext.errorData.statusCode}</td>
</tr>
<tr valign="top">
<td><b>Stack trace:</b></td>
<td>
<c:forEach var="trace"
items="${pageContext.exception.stackTrace}">
<p>${trace}</p>
</c:forEach>
</td>
</tr>
<%
Throwable cause = pageContext.getException().getCause();
while(cause != null) {
%>
<tr valign="top">
<td><b>Caused by:</b></td>
<td>
<% out.println(cause); %>
</td>
</tr>
<tr valign="top">
<td><b>Stack trace:</b></td>
<td>
<%
StackTraceElement[] stackTrace = cause.getStackTrace();
for (int i = 0; i < stackTrace.length; i++) {
%> <p> <%
out.println(stackTrace[i]);
%> </p> <%
}
%>
</td>
</tr>
<% cause = cause.getCause(); //Get next cause for the while loop
}
if (cause == null){
%>
<tr valign="top">
<td><b>No further Cause</b></td>
</tr>
<%
}
%>
</table>
</body>
</html>
하지만, 못생긴 해킹이라고 생각합니다. 좀 더 우아하게 할 수있는 방법이 있습니까?
당신에게편집 감사합니다 "오류 페이지에 대한 JSTL 태그를 사용하여"라는 제목의 튜토리얼의 섹션에서 http://www.tutorialspoint.com/jsp/jsp_exception_handling.htm