2

here is my test: 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>

if accessing test.action with ajax(jQuery),the error.jsp is returned in json type. How to make the browser redirect to the error.jsp.

Please advise.

Thanks a lot!!

LENS
  • 95
  • 1
  • 7

1 Answers1

0

There is not so much you can do on the server side, because the ajax client is the one that needs to do the handling.

You need to send the exception (or at least some marker that an exception occurs (for example a http status 500)) to the client (browser) and the ajax error handler must do the redirect (most ajax libs have some error handling function).

Ralph
  • 118,862
  • 56
  • 287
  • 383
  • thx,well,I should make every ajax function to hand the error, since in my project,this aspect weaves many methods. is there any more loose coupling structure possiblely – LENS Nov 29 '13 at 11:04
  • You mean AOP for Java Script? - I dont know any, but maybe there is one. – Ralph Nov 29 '13 at 11:11
  • em...i found this:http://stackoverflow.com/questions/1005486/javascript-aop-libraries – LENS Nov 29 '13 at 12:41