---
title: "struts2异常处理配置"
author: "miracle9i"
date: "2008-08-24T21:43:12Z"
tags: []
slug: "struts2"
draft: false
lastmod: "2008-08-24T21:43:12Z"
id: 232146
url: "https://miracle9i.iteye.com/blog/232146"
---

可将异常完全抛给struts2框架进行处理。
为实现异常处理，strust2配置了拦截器进行处理：

```XML

<interceptors>
	<interceptor name="exception" class="com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor"/>
</interceptors>	
<interceptor-stack name="defaultStack">
		<interceptor-ref name="exception"/>
</interceptor-stack>

```


异常捕捉的处理：

局部异常映射：在<action.../>中
全局异常映射，在<global-exception-mappings.../>中

```XML

<exception-mapping result="" exception="package.异常类"></exception-mapping>
属性详解：
	exception:指定该异常映射所设置的异常类型
	result:指定Action出现异常时，系统转入此属性所指向的结果
		全局映射指向global-result下的result
		局部映射指向本Action下的result

```



页面输出异常信息：

```XML
<s:property value="exception"/>输出异常对象本身
```


```XML
<s:property value="exceptionStack"/>输出异常堆栈信息
```