2012-09-27 89 views
0

好吧,所以我有一個奇怪的情況。我基本上創建了以前工作的這個JSP頁面,或者至少在Eclipse運行代碼時顯示頁面時打開一個新選項卡。但是今天,當我回到查看我創建的表單時,它基本上閃爍新標籤一秒鐘,然後自動關閉。我在控制檯或tomcat日誌中沒有收到任何錯誤,所以我不確定發生了什麼。我試圖在同一個項目中創建一個新的JSP文件(沒有相同的代碼),並且它正確加載。有沒有人有類似問題的經驗?JSP頁面不會在Eclipse中打開

下面是我的代碼...

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

恩,這可能聽起來很愚蠢,但我在末尾看到一個腳本標籤,上面寫着「window.close()」。你會不會意外地絆倒?我認爲腳本應該在頭部而不是身體中聲明? –

+0

我認爲這可能就是這樣,但我嘗試創建一個新項目,取出該項目,以及代碼的整個「

」部分,但我仍然遇到同樣的問題。另外,它在今天之前使用'window.close()'工作。 –

+1

我明白了,你知道什麼改變了嗎?我所知道的是,我非常確定腳本應該放在標題中。我只能假設你以某種方式提交你的表格。 –

回答

0

嗯,這是非常愚蠢的。所以我創建了另一個新的jsp文件,使用相同的代碼,除了<script>標記中的代碼,並且一切正常。然後我重新添加了<script>標籤,並且它在第一次運行良好。但是,下次我去試一試時,原來的問題再次出現了。然後,當我再次刪除<script>標籤時,問題仍然存在。所以無論什麼原因,似乎一旦你添加了window.close(),它會永久保留在頁面上?

相關問題