private String message;
         if(id == 1)
            try {
throw new BusinessProcessException("业务逻辑执行异常");
} catch (BusinessProcessException e) {
e.printStackTrace(); }
要把异常的信息message 传递到Business.jsp页面,怎么传递?怎么跳转?谢谢!

解决方案 »

  1.   

    不要在这里catch,让Business.jsp catch 这个异常
      

  2.   


    public static void main(String[] args){
    // TODO Auto-generated method stub
    try {
    get(1);
    } catch (Exception e) {
    e.printStackTrace();
    }
    }

    private static void get(int n) throws Exception{
    if(n == 1){
    throw new Exception();
    }
    }
      

  3.   


    public class Test{
        private static void get(int n) throws Exception{
            if(n == 1){
                throw new Exception();
            }
        }
    }
    index.jsp
    <%
     try
     {
      Test.get(1);
      response.sendRedirect("success.jsp");
     }
      catch(Exception ex)
    {
       response.sendRedirect("error.jsp");
    }
    %>
      

  4.   

    不写 try  catch() 提示有错误。
    要把异常的信息message 传递到Business.jsp页面,怎么传递?怎么跳转?谢谢!
      

  5.   

    再jsp页面直接打印吧,用PrintWriter保装一下out,把异常打到out上<%
             private String message;
             if(id == 1)
                   try {
                    throw new BusinessProcessException("业务逻辑执行异常");
                } catch (BusinessProcessException e) {
                    e.printStackTrace(new java.io.PrintWriter(out));
                }
    %>
      

  6.   

    参考下面的代码,就不会提示有错了public void method(int id) throws BusinessProcessException{
           if(id == 1){
                  throw new BusinessProcessException("业务逻辑执行异常");
           }
    }
      

  7.   


    public class MyException  extends ActionSupport{
    private int id;
    private String message;

    public  String execute() throws Exception{
    if(id == 1)

    throw new BusinessProcessException("业务逻辑执行异常");

    else if(id==2)

    throw new SqlErrorException("操作数据库执行异常");

    else if(id==3)

    throw new TftsException("传输层异常");

    else if(id==4)

    throw new WorkFlowException("工作流交互异常");
    else

    return message;

    }}
    要把异常的信息message 传递到Business.jsp页面,
    怎么传递?怎么跳转?
    谢谢!
      

  8.   

    代码执行到 throw new BusinessProcessException("业务逻辑执行异常")时, 他就已经自动跳转了,如果外层代码有 try{}catch(BusinessProcessException){} 这样的结构,就自动跳转到catch下的代码, 如果没有这样的结构,就会跳出当前方法, 回到调用这个方法的地方, 同样检查有没有try{}catch结构, 没有就继续向上层跳转,  直到有 try{}catch而你这里只需要在Business.jsp中调用这个方法的地方 try{}catch就可以了