JWorld@TW the best professional Java site in Taiwan
      註冊 | 登入 | 全文檢索 | 排行榜  

» JWorld@TW » Servlet/JSP 討論區  

按列印兼容模式列印這個話題 列印話題    把這個話題寄給朋友 寄給朋友   
reply to postflat modego to previous topicgo to next topic
本主題所含的標籤
無標籤
作者 執行jsp網頁中的程式會出現錯誤訊息
yanyonyuen





發文: 39
積分: 0
於 2004-01-29 11:57 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
各位前輩好
我最近在寫畢業專題,遇到了問題
當要搜尋資料庫的資料時會出現Exception的錯誤訊息
錯誤訊息如下

java.lang.Exception: An exception occured while retrieving Maintain. java.lang.NullPointerException

出現錯誤訊息的地方我有特別註明
我已經測試好幾次都不成功,最後將程式重寫還是一樣
以下是我所執行的程式碼

這是剛要進入的jsp畫面
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<%@ page contentType = "text/html; charset=big5" %>
<html>
  <head>
    <title>Maintain_behind</title>
  </head>
  <body>
    <center><font face = "標楷體" ; size = 30>
      <p>
        <b>
          電腦維修後端系統
        </b>
      </p>
    </font></center>
    
    <%--區隔前後的表格--%>
        <center><font face = "標楷體" ; size = 30>
          <p>
            <b>
            </b>
          </p>
        </font></center>
    <%--區隔前後的表格--%>
    <form name = "button1" method = "POST" action = "Maintain_enter.jsp">
      <table align = center>
        <td align = "center">
          <input type = "submit" value = "工程師維修系統"> //此為要登入的按鈕
        </td>
      </table>
    </form>
    
    <form name = "button2" method = "POST" action = "Admin_search.jsp">
      <table align = center>
        <td align = "center">
          <input type = "submit" value = "管理者搜尋及排班系統">
        </td>
      </table>
    </form>
    
    <form name = "button3" method = "POST" action = "Student_search.jsp">
      <table align = center>
        <td align = "center">
          <input type = "submit" value = "學生電腦查詢系統">
        </td>
      </table>
    </form>


登入之後輸入帳號密碼的畫面
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<%@ page language = "java" contentType = "text/html; charset=big5" %>
<html>
  <head>
    <MEAT http-equiv = "content-type" CONTENT = "text/html" ; charset = "big5">
    <title>Maintain_enter</title>
  </head>
  <body>
    <center><font face = "標楷體" ; size = 30>
      <p>
        <b>
          工程師維修系統
        </b>
      </p>
    </font></center>
    
    <%--區隔前後的表格--%>
        <center><font face = "標楷體" ; size = 30>
          <p>
            <b>
            </b>
          </p>
        </font></center>
    <%--區隔前後的表格--%>
    <form action = "CheckUser.jsp" method = "POST">
      <table align = center>
     <tr>
        <td align = "center">
          <input type = "text" name = "account" size = "20">
        </td>
     </tr>
       <tr>
        <td align = "center">
          <input type = "password" name = "passw" size = "20">
        </td>
       </tr>
     <tr>
        <td align = "center">
          <input type = "submit" value = "確定">
        </td>
     </tr>
      </table>
    </form>
  </body>
</html>


該帳號密碼會透過一個java程式作判斷,以下是判斷的jsp及java程式

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<%@ page language = "java"
     import = "java.io.* , java.util.*" contentType = "text/html; charset=big5" %>
 
<jsp:useBean id = "chk" class = "com.validate.test"/>
 
    <%
    request.setCharacterEncoding("Big5");
      String account = request.getParameter("account");
      String passw = request.getParameter("passw");
    if(chk.check(account, passw)){ %>    
   <jsp:forward page = "Maintain_table1.jsp" />
   <% }else{ %>
   <jsp:forward page = "ban.jsp" />
     <% } %>


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package com.validate;
 
import java.util.*;
 
public class test{
 
 
  public test() {}
 
  
  
  public boolean check(String name, String password){
 
  String n1 = "n89090104";
  String n2 = "n89090092";
  String n3 = "n89090041";
  String n4 = "n89090030";
  String n5 = "n89090012";
  String n6 = "n89090033";
  String p = "mustmis";
 
  if(name.equals(n1) && password.equals(p)){
   boolean a = true;
  return a;
  }else if(name.equals(n2) && password.equals(p)){
   boolean a = true;
  return a;
  }else if(name.equals(n3) && password.equals(p)){
   boolean a = true;
  return a;
  }else if(name.equals(n4) && password.equals(p)){
   boolean a = true;
  return a;
  }else if(name.equals(n5) && password.equals(p)){
   boolean a = true;
  return a;
  }else if(name.equals(n6) && password.equals(p)){
   boolean a = true;
  return a;
  }else{
   boolean a = false;
  return a;
  }
  }
}


當經過CheckUser.jsp判斷之後,若是正確將會forword到Maintain_table1.jsp的畫面
以下是Maintain_table1.jsp及該介面的java(Maintain_engineer.java)程式

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<body>
  <form>
    
    <table border = 1>
    <th>編號</th>
    <th>填單日期</th>
    <th>上課教室</th>
    <th>排數</th>
    <th>台數</th>
    <th>維修狀態</th>
      <% 
      table.connect();
                    ResultSet rs = table.viewMaintain1();  //這行是出現錯誤的地方                    
                    while (rs.next()) {
      String number;
      String sysTime;
      String classroom;
      String cpNum1;
      String cpNum2;
      String state;
 
      number = rs.getString("number");
      if(rs.wasNull()) {
        number = null;
      }
    %>
    <tr>
    <td><%= number %></td>
 
    <%
          sysTime = rs.getString("sysTime");
      if(rs.wasNull()) {
        sysTime = null;
      }
    %>
    
    <td><%= sysTime %></td>
 
       <%
          classroom = rs.getString("classroom");
      if(rs.wasNull()) {
        classroom = null;
      }
    %>
    
    <td><%= classroom %></td>
 
     <%
          cpNum1 = rs.getString("cpNum1");
      if(rs.wasNull()) {
        cpNum1 = null;
      }
    %>
    
    <td><%= cpNum1 %></td>
 
     <%
          cpNum2 = rs.getString("cpNum2");
      if(rs.wasNull()) {
        cpNum2 = null;
      }
    %>
    
    <td><%= cpNum2 %></td>
 
     <%
          state = rs.getString("state");
      if(rs.wasNull()) {
        state = null;
      }
    %>
    
    <td><%= state %></td>
      <td>
      <form action = "case-engineer.jsp" method = "POST">
      <input type = "hidden" name = "number" value = '<%= number %>'>
      <input type = "submit" name = "enter" value = "內容">
    </form>
      </td>
    </tr>
    <% } %>
    <% table.disconnect(); %>
    </table>
  </form>
</body>
</html>


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package com.database;
 
import java.sql.*;
import java.util.*;
 
public class Maintain_engineer{
  String error;
    Connection con;
 
  static{
    try{
      String driver = "com.microsoft.jdbc.sqlserver.SQLServerDriver";
      Class.forName(driver);
    }
    catch(Exception e){
      e.printStackTrace();
    }
  }
 
  public Maintain_engineer(){}
 
  public void connect() throws SQLException,Exception{
    try{
      Connection con = DriverManager.getConnection("jdbc:Microsoft:sqlserver://must-project:1433;DatabaseName=SCHOOL","sa","must");
    }
    catch(SQLException cnfe){
      error = "SQLException: Could not connect to database. " + cnfe.toString();
      throw new SQLException(error);
    }
    catch(Exception e){
      error = "Exception: An unknown error occurred while connecting to database. " + e.toString();
      throw new Exception(error);
    }
  }
 
    public void disconnect() throws SQLException{
      try{
        if(con != null){
          con.close();
        }
      }
      catch(SQLException sqle){
        error = "SQLException: Unable to close the database connection. " + sqle.toString();
        throw new SQLException(error);
      }
    }
 
    public ResultSet viewMaintain1() throws SQLException, Exception{
      ResultSet rs = null;
      try{
        Statement stmt = con.createStatement();
        rs = stmt.executeQuery("SELECT number, sysTime, classroom, cpNum1, cpNum2, state " +
                                       "FROM Maintain, Maintain_state " +
                                       "where Maintain.engineers = '顏永源' " +
                                       "and Maintain.statenum = 2 " +
                                       "and Maintain.statenum = Maintain_state.statenum " +
                                       "ORDER BY number ");
      }
      catch(SQLException sqle){
        error = "SQLException: Could not execute the query. " + sqle.toString();
        throw new SQLException(error);
      }
      catch(Exception e){
        error = "An exception occured while retrieving Maintain. " +e.toString();  //這是丟出錯誤訊息的地方        
                                                                throw new Exception(error);
      }
      return rs;
    }
  }


browser edited on 2004-01-29 12:02
reply to postreply to post
話題樹型展開
人氣 標題 作者 字數 發文時間
2291 執行jsp網頁中的程式會出現錯誤訊息 yanyonyuen 10816 2004-01-29 11:57
1270 Re:執行jsp網頁中的程式會出現錯誤訊息 weaker 3906 2004-01-29 16:24
1215 Re:執行jsp網頁中的程式會出現錯誤訊息 swpoker 107 2004-01-29 23:15
» JWorld@TW »  Servlet/JSP 討論區

reply to postflat modego to previous topicgo to next topic
  已讀文章
  新的文章
  被刪除的文章
Jump to the top of page

JWorld@TW 本站商標資訊

Powered by Powerful JuteForum® Version Jute 1.5.8