【问题标题】:Custom error page is not being displayed in chrome自定义错误页面未在 chrome 中显示
【发布时间】:2013-11-09 06:43:43
【问题描述】:

下面是我的 JdbsJsp.java 代码

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="java.sql.*" errorPage="/ErrorPage.jsp"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <%
            try
            {
                Class.forName("com.mysql.jdbc.Driver");
                Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/saumil","root","root");
                Statement stmt=con.createStatement();
                ResultSet rs=stmt.executeQuery("select * from emp");
                while(rs.next())
                {
                    out.println(rs.getInt(1)+" "+rs.getString(2));
                }
            }
            catch(Exception e)
            {

            }

        %>
    </body>
</html>

而我的错误页面如下,

<%@page isErrorPage="true"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <h1>An Exception has occured(probably SQLException)</h1>
        <%=exception.getMessage()%>
    </body>
</html>

我特意将表名设置为'emp'(数据库中没有这样的表)来显示错误页面。但是,我没有显示错误页面,而是得到了一个完全空白的屏幕。没有显示“发生异常(可能是 SQLException)”的消息。 希望有人能指导我。

【问题讨论】:

    标签: java jsp google-chrome exception


    【解决方案1】:

    在你的 JdbcJsp.jsp 页面中而不是写,

    catch(Exception e)
    {
    
    }
    

    写,

    finally
    {
    
    }
    

    据我所知,“catch”可能会阻止您的自定义异常页面显示。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-10
      • 2013-08-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-13
      相关资源
      最近更新 更多