简体   繁体   English

JSP页面将无法在Eclipse中打开

[英]JSP Page Will Not Open in Eclipse

Okay, so I have a weird situation. 好吧,我的情况很奇怪。 I basically created this JSP page that was working previously, or at least in the sense that Eclipse would open a new tab with the page displayed when I ran the code. 我基本上创建了这个以前运行过的JSP页面,或者至少从某种意义上来说,就是说Eclipse将在运行代码时打开一个新选项卡,并显示该页面。 But today, when I went back in to look at the form I had created, it basically flashes the new tab for a second and then automatically closes. 但是今天,当我回过头来查看创建的表单时,它基本上会在新选项卡上闪烁一秒钟,然后自动关闭。 I am not getting any errors in the console or the tomcat logs, so I'm not sure what is going on. 我在控制台或tomcat日志中没有收到任何错误,所以我不确定发生了什么。 I tried creating a new JSP file (without the same code) in the same project and it loaded correctly. 我尝试在同一项目中创建一个新的JSP文件(没有相同的代码),并正确加载了该文件。 Has anyone had any experience with a similar issue? 有没有人有过类似问题的经验?

Below is my code... 下面是我的代码...

<%@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>

Well this is pretty silly. 好吧,这很愚蠢。 So I created another new jsp file, with the same code, except for the code in the <script> tag and everything worked fine. 因此,我用相同的代码创建了另一个新的jsp文件,但<script>标记中的代码除外,并且一切正常。 I then re-added the <script> tag and it worked fine the first time. 然后,我重新添加了<script>标记,并且第一次运行良好。 However, the next time I went to try it, the original problem occurred again. 但是,下次我去尝试时,原来的问题又出现了。 Then when I went to remove the <script> tag once more, the issue still remained. 然后,当我再次删除<script>标记时,问题仍然存在。 So whatever reason, it seems once you add the window.close() , it permanently stays on the page? 因此,无论window.close()什么原因,似乎一旦添加window.close() ,它就会永久停留在页面上?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM