Skip to content

Commit 6f23804

Browse files
committed
Example how to use global exceptions mapping
git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@1073268 13f79535-47bb-0310-9956-ffa450edef68
1 parent 1abb426 commit 6f23804

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

apps/blank/src/main/resources/example.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<struts>
77

8-
<package name="example" namespace="/example" extends="struts-default">
8+
<package name="example" namespace="/example" extends="default">
99

1010
<action name="HelloWorld" class="example.HelloWorld">
1111
<result>/example/HelloWorld.jsp</result>

apps/blank/src/main/resources/struts.xml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,18 @@
88
<constant name="struts.enable.DynamicMethodInvocation" value="false" />
99
<constant name="struts.devMode" value="false" />
1010

11-
<include file="example.xml"/>
11+
<package name="default" namespace="/" extends="struts-default">
1212

13+
<default-action-ref name="index" />
1314

15+
<global-results>
16+
<result name="error">/error.jsp</result>
17+
</global-results>
18+
19+
<global-exception-mappings>
20+
<exception-mapping exception="java.lang.Exception" result="error"/>
21+
</global-exception-mappings>
1422

15-
<package name="default" namespace="/" extends="struts-default">
16-
<default-action-ref name="index" />
1723
<action name="index">
1824
<result type="redirectAction">
1925
<param name="actionName">HelloWorld</param>
@@ -22,6 +28,8 @@
2228
</action>
2329
</package>
2430

31+
<include file="example.xml"/>
32+
2533
<!-- Add packages here -->
2634

2735
</struts>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
2+
<%@ taglib prefix="s" uri="/struts-tags" %>
3+
4+
<html>
5+
<head><title>Simple jsp page</title></head>
6+
<body>
7+
<h3>Exception:</h3>
8+
<s:property value="exception"/>
9+
10+
<h3>Stack trace:</h3>
11+
<pre>
12+
<s:property value="exceptionStack"/>
13+
</pre>
14+
</body>
15+
</html>

0 commit comments

Comments
 (0)