请问如何实现?详细点...

解决方案 »

  1.   

    首先你要接住异常,在CATCH中跳转另外个页面就可以了,在把异常原因保存下,异常页面显示了思密达
      

  2.   


    try{
    做点啥。
    } catch (Exception e) {
                request.setAttribute("message", "xxx出错了");
        request.getRequestDispatcher("error.jsp").forward(request,response); 
                      }
      

  3.   

    那我要把printStackTrace()里面的东西,在页面显示呢?
      

  4.   

    request.setAttribute("massage",e.printStackTrace());
    然后在error.jsp页面取得massage
      

  5.   

    Java code
    try{
    做点啥。
    } catch (Exception e) {
                request.setAttribute("message", "xxx出错了");
        request.getRequestDispatcher("error.jsp").forward(request,response); 
                      }
     request.setAttribute("message", "xxx出错了");//保存了错误信息在JSP上接受显示 ${message}
      

  6.   


    没人会这么做,谁会将这样的异常信息故意显示在页面?开发时,对于404、500之类的错误,会在配置文件中进行处理,进而转到一个配置好的错误页面提示。对于一些运行时异常,会直接在catch中进行处理。
      

  7.   

    <%@ page language="java" contentType="text/html;charset=UTF-8" isErrorPage="true" %><html>
      <head>
        <title>内部服务器错误</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta http-equiv="Cache-Control" content="no-cache">
    <meta http-equiv="Pragma" content="no-cache">
    <meta http-equiv="Expires" content="0">
    <script language="JavaScript" type="text/JavaScript">
    function showError() {
    var error = document.getElementById("exception");
    var s = error.style.display;
    error.style.display = (s == "none") ? "" : "none";
    }
    </script>  </head>  <body>
        <h2>内部服务器错误</h2>
    <hr>
    <div id="exception" style="color:blue">
          <pre>
    <%  
    if (exception != null) {
    exception.printStackTrace(new java.io.PrintWriter(out));
    exception.printStackTrace();

    exception = (Throwable) request.getAttribute("exception");
    if (exception != null) {
    exception.printStackTrace(new java.io.PrintWriter(out));
    exception.printStackTrace();

    %>
          </pre>
    </div>
      </body>
    </html>