代码之家  ›  专栏  ›  技术社区  ›  This 0ne Pr0grammer

JSP页面不会在Eclipse中打开

  •  0
  • This 0ne Pr0grammer  · 技术社区  · 13 年前

    好吧,所以我有一个奇怪的情况。我基本上创建了这个JSP页面,它以前是工作的,或者至少从某种意义上说,Eclipse会打开一个新的选项卡,其中显示了我运行代码时显示的页面。但今天,当我回去查看我创建的表单时,它基本上会闪烁新选项卡一秒钟,然后自动关闭。我在控制台或tomcat日志中没有收到任何错误,所以我不确定发生了什么。我尝试在同一项目中创建一个新的JSP文件(没有相同的代码),它加载正确。有人经历过类似的问题吗?

    下面是我的代码。。。

    <%@page import="java.sql.*"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
        <html>
            <head>
                <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
                    <title>Code Selector</title>
            </head>
            <body> 
                <h1>Please select the applicable codes:</h1> 
                <select name='Code' onchange="showState(this.value)">  
                <option value="none">Select a code</option>  
                <%
                    //Pulls the ids and decriptions from the codes table and stores them in the first drop down
                    try
                    {
                        Class.forName("driverName").newInstance();  
                        Connection con = DriverManager.getConnection("serverURL","username","password");  
                        Statement stmt = con.createStatement();  
                        ResultSet rs = stmt.executeQuery("select id, descr from codes");
    
                        while(rs.next())
                        {
                            %>
                                <option value="<%=rs.getString(1)%>"><%=rs.getString(1)%> <%=rs.getString(2)%></option>  
                            <%
                        }
    
                        //Closes the database connection
                        stmt.close();
                        con.close();
                    }
                    catch (ClassNotFoundException e)
                    {
                        System.err.println("ClassNotFoundException: " + e.getMessage());
                    } 
                    catch (SQLException e)
                    {
                        System.err.println("SQLException: " + e.getMessage());
                    }
                    catch (Exception e)
                    {
                        System.err.println("Generic Exception: " + e.getMessage());
                    }       
                %>
                </select>  
                <br>
                <br>
                <select name='Code2' onchange="showState(this.value)">  
                <option value="none">Select a code</option>  
                <%
                    //Pulls the ids and decriptions from the codes table and stores them in the second drop down
                    try
                    {
                        Class.forName("driverName").newInstance();  
                        Connection con = DriverManager.getConnection("serverURL","username","password");  
                        Statement stmt = con.createStatement();  
                        ResultSet rs = stmt.executeQuery("select id, descr from codes");
    
                        while(rs.next())
                        {
                            %>
                                <option value="<%=rs.getString(1)%>"><%=rs.getString(1)%> <%=rs.getString(2)%></option>  
                            <%
                        }
    
                        //Closes the database connection
                        stmt.close();
                        con.close();
                    }
                    catch (ClassNotFoundException e)
                    {
                        System.err.println("ClassNotFoundException: " + e.getMessage());
                    } 
                    catch (SQLException e)
                    {
                        System.err.println("SQLException: " + e.getMessage());
                    }
                    catch (Exception e)
                    {
                        System.err.println("Generic Exception: " + e.getMessage());
                    }       
                 %>
                </select>
                <br>
                <br>
                <select name='otherCode' onchange="showState(this.value)">  
                <option value="none">Select a other code</option>  
                <%
    
                    //Pulls the ids and decriptions from the other codes table and stores them in the third drop down
                    try
                    {
                        Class.forName("driverName").newInstance();  
                        Connection con = DriverManager.getConnection("serverURL","username","password");  
                        Statement stmt = con.createStatement();
                        ResultSet rs2 = stmt.executeQuery("select id, descr from other_codes");
    
                        while(rs2.next())
                        {
                            %>
                                <option value="<%=rs2.getString(1)%>"><%=rs2.getString(1)%> <%=rs2.getString(2)%></option>  
                            <%
                        }
    
                        //Closes the database connection
                        stmt.close();
                        con.close();
                    }
                    catch (ClassNotFoundException e)
                    {
                        System.err.println("ClassNotFoundException: " + e.getMessage());
                    } 
                    catch (SQLException e)
                    {
                        System.err.println("SQLException: " + e.getMessage());
                    }
                    catch (Exception e)
                    {
                        System.err.println("Generic Exception: " + e.getMessage());
                    }       
                %>
          </select>
          <br> 
          <br>
          <form method = "post">
            <input type="submit" value="Submit">
            <%
                try
                {
                    String Code = request.getParameter("Code");
                    String Code2 = request.getParameter("Code2");
                    String otherCode = request.getParameter("otherCode");
    
                    Class.forName("driverName").newInstance();  
                    Connection con = DriverManager.getConnection("serverURL","username","password");  
                    Statement stmt = con.createStatement();
                    //ResultSet rs3 = stmt.executeQuery();
    
                    System.out.println("This is the first code: " + Code);
                    System.out.println("This is the second code: " + Code2);
                    System.out.println("This is the other code: " + otherCode);
    
                    con.close();
                    stmt.close();
    
                }
                catch (ClassNotFoundException e)
                {
                    System.err.println("ClassNotFoundException: " + e.getMessage());
                } 
                catch (SQLException e)
                {
                    System.err.println("SQLException: " + e.getMessage());
                }
                catch (Exception e)
                {
                    System.err.println("Generic Exception: " + e.getMessage());
                } 
            %>
            <script>
                window.close();
            </script>
          </form>
          </body> 
    </html>
    
    1 回复  |  直到 13 年前
        1
  •  0
  •   This 0ne Pr0grammer    13 年前

    这太傻了。因此,我创建了另一个新的jsp文件,除了 <script> 标签和一切都很好。然后我重新添加 <脚本> 标签,它第一次工作得很好。然而,下次我去尝试时,原来的问题又出现了。然后当我去移除 <脚本> 标签,问题仍然存在。因此,无论出于什么原因,一旦你添加 window.close() ,它会永久停留在页面上吗?