0

我正在使用与 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();
    }
}
4

1 回答 1

0

要么声明一个异常处理结果,要么返回一些有用的东西。

于 2012-03-04T23:02:52.030 回答