如何处理Struts 2用户定义的AJAX结果中抛出的异常?

问题描述 投票:0回答:1

我正在使用与AJAX请求一起使用的Struts 2用户定义结果。

当它抛出异常时,我得到一个html格式的“Struts问题报告”作为响应。这不是很有用。如何智能地处理这样的异常 - 调用相应的javascript errorResponse函数或将用户带到另一个页面?

public class MyResult implements Result {

    @Override
    public void execute(ActionInvocation invocation) {

        if (invocation.getStack().findValue("data") == null) {
            throw MyException("Data is bad.");
        }

        PrintWriter responseStream =
            ServletActionContext.getResponse().getWriter();
        responseStream.println("Data is good.");
        responseStream.close();
    }
}
java ajax struts2 struts-config
1个回答
0
投票

要么声明一个exception handling result,要么回流一些有用的东西。

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.