spring异常处理如何跟struts配合?
public class UserAfterThrowing extends ActionSupport implements ThrowsAdvice {
public void afterThrowing(Method method,Object[] args,Object target,
Exception exception)throws Throwable{
System.out.println("throwing a exception:" +exception.toString());
System.out.println("成功回滚事务");
ServletActionContext.getResponse().sendRedirect("../error.jsp");
}
}
在applicationContext.xml里面:
<bean id="exceptionHandler1" class="com.yzj.aop.UserAfterThrowing"></bean>
<bean id="target" class="com.yzj.service.UserService"></bean>
<bean id="firstAop" class="org.springframework.aop.framework.ProxyFactoryBean"
p:interceptorNames="exceptionHandler1"
p:target-ref="target"
p:proxyTargetClass="true"
/>
上面的代码都没有问题 能成功捕获异常 也能成功回滚事务
但是。。。。
异常捕获到了之后 我只会根据ServletActionContext.getResponse().sendRedirect("../error.jsp");进入想要进入的页面
请问应该怎样和struts配合?
比如 如何返回字符串 “error” 给struts?
然后struts根据result进入对应的视图?
所有代码里面都没有try catch 和throws exception 都是利用ThrowsAdvice 来完成异常捕获的