这是我的测试:TestAspect
@Component
@Aspect
public class TestAspect {
@Before(value = "@annotation(testAnnotation)", argNames = "testAnnotation")
public void test(TestAnnotation testAnnotation) throws RuntimeException {
throw new RuntimeException("runtime exception");
}
}
测试注释
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface TestAnnotation {
}
测试动作
@Controller
@Result(name = ActionSupport.SUCCESS, type = "json")
public class TestAction extends ActionSupport {
private static final long serialVersionUID = 2680952388896234662L;
@TestAnnotation
public String execute() {
return SUCCESS;
}
}
Strust2 XML
<package name="default" extends="convention-default,json-default">
<interceptors>
<interceptor-stack name="mydefault">
<interceptor-ref name="defaultStack" />
<interceptor-ref name="json">
<param name="ignoreHierarchy">false</param>
<param name="excludeNullProperties">true</param>
</interceptor-ref>
</interceptor-stack>
</interceptors>
<default-interceptor-ref name="mydefault" />
<global-results>
<result name="error" type="redirect">/error.jsp</result>
</global-results>
<global-exception-mappings>
<exception-mapping
exception="java.lang.RuntimeException"
result="error" />
</global-exception-mappings>
</package>
如果使用ajax(jQuery)访问test.action,则将以json类型返回error.jsp。如何使浏览器重定向到error.jsp。
请指教。
非常感谢!!
在服务器端您无能为力,因为ajax客户端是需要处理的客户端。
您需要将异常(或至少发生异常的某些标记(例如,http状态500))发送到客户端(浏览器),并且ajax错误处理程序必须执行重定向(大多数ajax库具有某些错误处理功能) 。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句