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

» JWorld@TW » Java 新手區 » 例外/錯誤處理  

按列印兼容模式列印這個話題 列印話題    把這個話題寄給朋友 寄給朋友    訂閱主題
reply to postflat modego to previous topicgo to next topic
本主題所含的標籤
作者 輸出頁面抓不到資料
ktidings





發文: 7
積分: 0
於 2010-04-30 11:54 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
輸出頁面只有標題列
下面的資料都找不到
沒有錯誤碼
資料庫有資料、搜尋值沒錯誤
可以請各位高手幫我看一下程式錯誤在哪?

使用者搜尋頁面

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<%@ page language="java" contentType="text/html; charset=BIG5"
  pageEncoding="BIG5"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib prefix="s" uri="/struts-tags"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=BIG5">
<title>查詢</title>
</head>
<body>
<s:form action="search" namespace="/webaon">
  <s:textfield label="輸入查詢" name="sertxt"></s:textfield>
  <s:submit label="查詢" name="search" value="查詢"></s:submit>
</s:form>
</body>
</html>


搜尋的java
search.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
87
88
89
90
91
92
93
94
95
96
97
98
package webaon;
 
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
//import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;
import com.opensymphony.xwork2.ActionSupport;
import env.DBconn;
import env.ErrorMesg;
import env.field;
 
public class search extends ActionSupport {
  /**
   *
   */
  private static final long serialVersionUID = 1;
  private String sertxt;
  private ErrorMesg errorMesg;
  private Vector<ErrorMesg> vecError;
  private field o;
  private List<field> fields;
    private Connection con;
    
    public search()
    {
    this.con=DBconn.getConnection();  
    }
    
  public String execute() {
    
    ResultSet rs = null;
    fields = new ArrayList<field>();
    vecError = new Vector<ErrorMesg>();
 
    try {
    
    //  Statement stm = con.createStatement();
 
      // 查詢 SQL
    //  String SQL = ("select * from Master where iITEMID='"+sertxt+"'");
      String SQL = ("select * from Master ");
      PreparedStatement pstmt = con.prepareStatement(SQL);
 
      // 取得查詢結果
      rs = pstmt.executeQuery();
 
      // 塞查詢出的資料到 dataOBJs
      while (rs.next()) {
        o = new field();
        o.setiITEMID(rs.getString(1));
        o.setiITEMNAME(rs.getString(2));
        o.setiITEMTYPE(rs.getString(3));
        o.setiAUTHYN(rs.getString(4));
        o.setiDESCS(rs.getString(5));
        fields.add(o);
      }
      return SUCCESS;
      
             
    }
    catch (Exception e) {
      e.printStackTrace();
      //將錯誤訊息塞到 vecError,再由前端的 error.jsp 秀出
      errorMesg = new ErrorMesg();
      errorMesg.setErrormessage(e.toString());
      vecError.add(errorMesg);
      return ERROR;
    }
  }
 
  public String getSertxt() {
    return sertxt;
  }
 
  public void setSertxt(String sertxt) {
    this.sertxt = sertxt;
  }
 
    public List<field> getfields() {
        return fields;
    }
 
    public void setfields(List<field> fields) {
        this.fields = fields;
    }
 
    public Vector<ErrorMesg> getVecError() {
        return vecError;
    }
 
    public void setVecError(Vector<ErrorMesg> vecError) {
        this.vecError = vecError;
    }
}
 


field.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
package env;
 
public class field 
{
    
  private String iITEMID;
  private String iITEMNAME;
  private String iITEMTYPE;
  private String iAUTHYN;
  private String iDESCS;
 
  public String getiITEMID()  {return iITEMID; } 
  public void setiITEMID(String iITEMID) { this.iITEMID = iITEMID; }
 
  public String getiITEMNAME() { return iITEMNAME; } 
  public void setiITEMNAME(String iITEMNAME) { this.iITEMNAME = iITEMNAME; }
 
  public String getiITEMTYPE() { return iITEMTYPE; } 
  public void setiITEMTYPE(String iITEMTYPE) { this.iITEMTYPE = iITEMTYPE; }
 
  public String getiAUTHYN() { return iAUTHYN; } 
  public void setiAUTHYN(String iAUTHYN) { this.iAUTHYN = iAUTHYN; }
 
  public String getiDESCS() { return iDESCS; } 
  public void setiDESCS(String iDESCS) { this.iDESCS = iDESCS;  }
 
}


display.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
<%@ page language="java" contentType="text/html; charset=BIG5"
    pageEncoding="BIG5"%>
 
<%@ taglib prefix="s" uri="/struts-tags"%>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 
<html>
<head>
</head>
<style>
.dataO {border:0px solid blue;border-collapse:collapse;}
.dataO th{ background-color:#ddd;color:#666;text-align:left;border:1px
solid white;padding:5px;}
.dataO td{padding:5px;}
.dataO tr.odd {background-color:#fafbff;}
.dataO tr.even {background-color:#f4f4ff;}
</style>
<body>
<table class="dataO">
<tr>
<th>iITEMID</th>
<th>iITEMNAME</th>
<th>iITEMTYPE</th>
<th>iAUTHYN</th>
<th>iDESCS</th>
</tr>
<!-- 底下這個標籤主要是透過回圈將 java.util.Collection 類別的物件內容取出,我在
這個例子用了 List(資料庫取出的內容) 及 Vector(針對 errorMessage),底下 value
的值 fields 是對應到程式 Search.java 裡的變數,id 的值為它的type field-->
<s:iterator value="fields" id="field" status="dataO_stat">
<tr class="<s:if test="#dataO_stat.odd ==true">odd</s:if><s:else>even</s:else>">
<td><s:property value="iITEMID" /></td>
<td><s:property value="iITEMNAME" /></td>
<td><s:property value="iITEMTYPE" /></td>
<td><s:property value="iAUTHYN" /></td>
<td><s:property value="iDESCS" /></td>
</tr>
</s:iterator>
</table>
</body>
</html>


reply to postreply to post
話題樹型展開
人氣 標題 作者 字數 發文時間
1017 輸出頁面抓不到資料 ktidings 5011 2010-04-30 11:54
» JWorld@TW »  Java 新手區 » 例外/錯誤處理

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