여기 내 테스트 : TestAspect
@Component
@Aspect
public class TestAspect {
@Before(value = "@annotation(testAnnotation)", argNames = "testAnnotation")
public void test(TestAnnotation testAnnotation) throws RuntimeException {
throw new RuntimeException("runtime exception");
}
}
TestAnnotation
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface TestAnnotation {
}
TestAction
@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에 액세스하면 error.jsp가 json 유형으로 반환됩니다. 브라우저를 error.jsp로 리디렉션하는 방법.
조언하십시오.
감사합니다 !!
서버 측에서 할 수있는 일이 많지 않습니다. 왜냐하면 ajax 클라이언트가 처리를해야하기 때문입니다.
클라이언트 (브라우저)에 예외 (또는 예외가 발생하는 적어도 일부 마커 (예 : http 상태 500))를 보내야하며 ajax 오류 처리기가 리디렉션을 수행해야합니다 (대부분의 ajax 라이브러리에는 오류 처리 기능이 있음) .
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다