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

» JWorld@TW » Servlet/JSP 討論區  

按列印兼容模式列印這個話題 列印話題    把這個話題寄給朋友 寄給朋友   
reply to topicthreaded modego to previous topicgo to next topic
本主題所含的標籤
無標籤
作者 Re:[問題]即時多層下拉選單 [Re:ㄚ孝]
joshua





發文: 2
積分: 0
於 2004-11-17 17:27 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
範例找不到, 乾脆寫一個新的:

程式主體, 還是借用 browser 大大的程式, 只是做了點小修改, 成為可以隨時撈db的版本

這隻範例裡頭的 java script 只能在 ie 上面跑, 在mozilla上面會有問題, 有興趣可以改改看

main.jsp
1
2
3
4
5
6
7
8
9
10
<%@ page contentType="text/html; charset=Big5" import="java.sql.*,java.util.*,java.io.*"%>
<html>
  <head>
    <title>MAIN (main.jsp)</title>
  </head>
  <frameset rows="*%,50%" frameborder="NO" border="0" framespacing="0">
    <frame name="showFrame" src="show.jsp" frameborder="NO">
    <frame name="submitFrame" src="submit.jsp" >
  </frameset>
</html>


show.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
<%@ page contentType="text/html; charset=Big5" import="java.sql.*,java.util.*,java.io.*"%>
 
<html>
<head>
<title> show </title>
</head>
 
<body>
<form name="form" onsubmit="false;">
 
<select name="select01" onChange="Javascript:changelist();">
<option value="1" selected>國別</option>
<option value="2">女演員</option>
</select>
                                                                              
<div id="newOption"></div>
 
</form>
</body>
</html>
 
<SCRIPT LANGUAGE="JavaScript">
<!--
function changelist()
{
    window.parent.submitFrame.form.select01.value = form.select01.value;
    window.parent.submitFrame.form.workingType.value = "search";
    window.parent.submitFrame.form.submit();
}
-->
</SCRIPT>


submit.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
<%@ page contentType="text/html; charset=Big5" import="java.sql.*,java.util.*,java.io.*"%>
 
<%
String select01 = (String)request.getParameter("select01");
String workingType   = (String)request.getParameter("workingType");
%>
 
<html>
<head>
<title> submit </title>
</head>
<SCRIPT LANGUAGE="JavaScript">
<!--
function init()
{
  
<%
if( "search".equals(workingType) )
{
  /***********與DB查詢有關的部分省略***********/
  if( "1".equals(select01) )
    out.println("window.parent.showFrame.document.all.newOption.innerHTML='<select name=select02><option value=1>台灣<option value=2>中國</select>'");
  else 
    out.println("window.parent.showFrame.document.all.newOption.innerHTML='<select name=select02><option value=1>田麗<option value=2>葉祖媚</select>'");
}
%>  
  
}
-->
</SCRIPT>
<body onload="init();">
<form name="form" method="post" action="submit.jsp">
  <input type="hidden" name="select01" value="">
  <input type="hidden" name="workingType" value="">
</form>
</body>
</html>


DB的部分我省略掉了, 看需求自行修改


joshua edited on 2004-11-17 17:32
reply to postreply to post
作者 Re:[問題]即時多層下拉選單 [Re:ㄚ孝]
Madagascar





發文: 122
積分: 2
於 2004-12-04 02:06 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
最近都在使用JSTL的SQL tag來做下拉式選單內容填值工作....
您可以考慮使用JSTL 的SQL標籤搭配CORE的forEach來做....

如果又使用datasourc的方式會更有彈性與移植性....
提供您一個方向...

我個人是覺得省時又省力...Tongue


Madagascar edited on 2004-12-04 02:16
reply to postreply to post
作者 Re:[問題]即時多層下拉選單 [Re:Madagascar]
yannru





發文: 34
積分: 0
於 2004-12-07 16:19 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
Madagascar wrote:
最近都在使用JSTL的SQL tag來做下拉式選單內容填值工作....
您可以考慮使用JSTL 的SQL標籤搭配CORE的forEach來做....

如果又使用datasourc的方式會更有彈性與移植性....
提供您一個方向...

我個人是覺得省時又省力...Tongue

您好:
  但是JSTL不是無法與Javascript做結合嗎?
那又如何做到onChange的即時處理呢?
小弟我因為突破不了JSTL與Javascript的結合,
又回到JSP語法與Javascript結合的處理才解決說,
但就變成要做兩個connection database方式了,
請問要如何才能做到你說的方式呢?懇請賜教~~


reply to postreply to post
作者 Re:[問題]即時多層下拉選單 [Re:ㄚ孝]
Madagascar





發文: 122
積分: 2
於 2004-12-07 21:20 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
首先我建議您看看IBM的驅動程式下載的網站
它本身是用Struts寫的
是有做到您開版第一篇的需求....Big Smile

不過關於JSTL+JavaScript的「整合」問題....

首先資料是否經常性變動?
如果不常變動的話,可以只考慮JSP + JavaScript就好,其他就不要想了...Big Smile
如果常變動的話,JSTL+JavaScript我個人想想去都要查詢好幾次....Blush
如果要只查詢一次就要像您開版那樣需求
我目前也是想不出來...呵呵(不好意思Wink

附上IBM驅動程式下載網址供您參考
IBM驅動程式下載網站

不過這裡面還有涉及使用velocity的技術,這裡就不討論了....


Madagascar edited on 2004-12-08 10:26
reply to postreply to post
已完成:SCJP 1.4、SCWCD 1.3
今年目標:SCWCD 1.4、SCBCD 1.3
加油!!!
作者 Re:[問題]即時多層下拉選單 [Re:ㄚ孝]
small3





發文: 25
積分: 0
於 2004-12-13 09:52 user profilesend a private message to usersend email to small3reply 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.客戶要求共有11個下拉式選單的關連
2.希望不要有一個一個慢慢跳出的問題<==每onChange一次submit會有這個 問題

p.s:下拉式選單內容全都是來自DATABASE(但是內容異動性不常)
剛開始小弟也是使用 每觸發一次onChange就對server request一次
結果畫面會因此每 request就對後面關聯的下拉選單重新產生一次..

後來將所有的資料一次load到使用端(javaScript 的陣列中)
然後再由onChange去將key找出來..
這樣畫面幾乎讓你感覺不出來有改變...
不過這種寫法比較不需要高深的程式技術...也就比較容易完成..
提供給您一個參考...

內容如有誤請指教..謝謝


reply to postreply to post
尊重別人就是看重自己
作者 Re:[問題]即時多層下拉選單 [Re:ㄚ孝]
EPHT





發文: 1
積分: 0
於 2004-12-18 09:45 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
之前作專案時也有遇到類似的需求...

因為當時選單的資料量不大,所以是在後端一次將資料取得之後,再配合 JavaScript....

為了讓畫面可以簡潔一點,寫了一組 tag 將 Java 中的 Collection, Map, String[], String[][], String[][][] 轉換為 JavaScript 的 Array 使用...

tag 的 Source Code 在附檔的 ScriptArray.jar 中......
其中,使用到的 RequestUtils 是從 Struts 借用來的
範列 demo.jsp 中除了使用 自訂的 tag 外,也使用了 jakarta 的 input tag,提供給有興趣的參考參考囉:
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
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<%@ page language="java" contentType="text/html; charset=BIG5" pageEncoding="BIG5"%>
<%@ page import="java.util.HashMap" %>
 
<%@ taglib uri="/demo" prefix="demo" %>
<%@ taglib uri="/input" prefix="input" %>
 
<%
/* =========== (A) 此段模擬後端取得之資料 =========== */
HashMap countryMap = new HashMap();
countryMap.put("--", "--");
countryMap.put("台灣", "Taiwan");
countryMap.put("日本", "Japan");
 
String[][][] cities = new String[3][][];
 
cities[0] = new String[][]{{"--", ""}, {"--","--"}};
cities[1] = new String[][]{{"Taiwan",""}, {"台北", "Taipei" }, {"台南", "Tainan" }};
cities[2] = new String[][]{{"Japan",""}, {"東京", "Tokyo" }, {"京都", "Kyoto" }};
 
String[][][] others = new String[5][][];
 
others[0] = new String[][]{{"--", ""}, {"--","--"}};
others[1] = new String[][]{{"Taipei",""}, {"台北_1", "Taipei1" }, {"台北_2", "Taipei2" }};
others[2] = new String[][]{{"Tainan",""}, {"台南_1", "Tainan1" }, {"台南_2", "Tainan2" }};
others[3] = new String[][]{{"Tokyo",""}, {"東京_1", "Tokyo1" }, {"東京_2", "Tokyo2" }};
others[4] = new String[][]{{"Kyoto",""}, {"京都_1", "Kyoto1" }, {"京都_2", "Kyoto2" }};
/* =========== (A) End ============================= */
 
pageContext.setAttribute("cities", cities);
pageContext.setAttribute("others", others);
%>
 
<meta http-equiv="Content-Type" content="text/html; charset=big5">
 
<TITLE>DEMO</TITLE>
 
<demo:ScriptArray varName="varCityOptions" scope="page" name="cities"/>
<demo:ScriptArray varName="varOtherOptions" scope="page" name="others"/>
 
<Script>
function changeOption( master, detail, detailOption ){
  var varValue = master.value;
  var varMasterNum = detailOption.length;
 
  for(var i=0; i<varMasterNum ; i++){  
    if( varValue == detailOption[i][0][0] ){
      initOption( detail );
      
      var varDetailNum = detailOption[i].length;
      detail.length = varDetailNum;      
      for( var j=1; j<varDetailNum ; j++){
        detail.options[ j ] = new Option( detailOption[ i ][ j ][ 0 ],detailOption[ i ][ j ][ 1 ] );    
      }
      break;
    }
  }
}
 
function initOption( target ){
  if( target.length ){
    target.length = 1;
    target.options[ 0 ] = new Option("--", "--" );              
  }
}
</Script>
</head>
 
<body>
 
<input:select name="country" options="<%=countryMap%>" 
attributesText=" onchange='changeOption( this, city ,  varCityOptions); initOption( other )' " />
 
<select name="city" onchange='changeOption( this, other ,  varOtherOptions)'>
  <option value="--">--</option>
</select>
 
<select name="other" >
  <option value="--">--</option>
</select>
 
</body>
</html>
 


- End -

ScriptArray.jar (4.79k)


EPHT edited on 2004-12-23 14:44
reply to postreply to post
作者 Re:[問題]即時多層下拉選單 [Re:yafeng]
javaer

OMG!



發文: 87
積分: 1
於 2004-12-20 00:40 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
基本上
個人認為一次讀進所有資料 - 不管是前端或是後端,
是比較好做的方法,但試想,使用者並不會需要所有的資料
所以其餘用不到的資訊要不會浪費網路的頻寬,要不就吃掉記憶體

如果不怕麻煩,又要顧效能的話
其實我想可以搭配javascript做出remote scripting的效果
再把查到資料留在前端,這樣每次onChange所造成的停頓只會發生在第一次
以前有在這邊看過類似的討論
供大家做個參考
Clown


javaer edited on 2004-12-20 00:43
reply to postreply to post
作者 Re:[問題]即時多層下拉選單 [Re:jonz]
pulse





發文: 8
積分: 0
於 2005-04-18 23:22 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
jonz wrote:
我的做法是:
還給jsp一個乾淨的面目

<SELECT name='NATION' onChange='submit();'>
<OPTION>..略..
<OPTION>..略..
..略..
</SELECT>

<SELECT name='CITY'>
<%=regionObj.getCityOptions(request.getParameter("NATION"))%>
</SELECT>


其中 regionObj 是自定的物件,
其中要有public Stirng getCityOptions(String nation)這個method;
如果要做三層加一個鄉鎮,
只要在SELECT CITY中加上onclick='submit();'
再多做一個public Sttring getTownOptions(String city)的method就可以了,
要再加幾層都不是問題。

至於說你要每次都去DB裡面撈,或放在web server的記憶體,
就看你的考量了。

如果你功力更好的話,把它再做成tag看起來就更完美了。

我的經驗是:不要把太多java code留在JSP上(<%......%>這種),
因為JSP相較之下比較不好debug(小弟公司用的是WSAD,可以trace JSP喔~~)
而且會讓JSP變的很亂很難讀。

另外畫面html物件的控制要儘量用Java Script 來做,
不要寫一堆像是:
1
2
3
4
5
<%if(A==0){%>
  <SELECT>......</SELECT>
<%}else{%>
  <SELECT>.....</SELECT>
<%}>

這要是多起來…會讓人抓狂的…


您好
請問一下您的方法中
onChange='submit();'
是指submit到原本頁面嗎
如果是的話
如何讓name='NATION' 的值保留下來(不變)

我試的結果
1
<SELECT name='CITY'>  <%=regionObj.getCityOptions(request.getParameter("NATION"))%></SELECT>

是成功的撈到資料庫的資料
但是前一個select卻回到最初未選前
導致無法將這2個select的值正確送到欲處理的頁面
請前輩不吝指教


reply to postreply to post
java......等等我啊.....
作者 Re:[問題]即時多層下拉選單 [Re:ㄚ孝]
yulie





發文: 2
積分: 0
於 2006-06-06 12:47 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
<%@ page contentType="text/html; charset=utf-8" %>
<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<TITLE>動態下拉式選單 (二階層):</Title></Head>

表單名稱為 myForm
<FORM Name="myForm">
  <SELECT Name="color" OnChange="Buildkey(this.selectedIndex);">
    <OPTION Value="應用數學系">應用數學系
    <OPTION Value="物理學系">物理學系
    <OPTION Value="心理學系">心理學系
    <OPTION Value="化學系">化學系
    <OPTION Value="生物科技學系">生物科技學系
  </Select>
  <SELECT Name="fruit">
    <option>請選擇科系:</option>
  </Select>

</Form>
</Body>
</Html>

<SCRIPT Language="JavaScript">
<!--
key=new ArrayDevil;
key[0]=new Array(10);
key[1]=new Array(10);
key[2]=new Array(9);
key[3]=new Array(9);
key[4]=new Array(3);
key[0][0]="張志豪 ";
key[0][1]="王承斌 ";
key[0][2]="呂淑鈴 ";
key[0][3]="陳建宏 ";
key[0][4]="周秋芬 ";
key[0][5]="林余昭 ";
key[0][6]="張德新 ";
key[0][7]="許大偉 ";
key[0][8]="謝俊男 ";
key[0][9]="楊鎮槐 ";
key[1][0]="陳秋豪 ";
key[1][1]="許經夌 ";
key[1][2]="朱祐諒 ";
key[1][3]="湯秀靜 ";
key[1][4]="張仲宏 ";
key[1][5]="李如玉 ";
key[1][6]="陳心誼 ";
key[1][7]="陳金枝 ";
key[1][8]="李魏堯 ";
key[1][9]="林澤義 ";
key[2][0]="林書� ";
key[2][1]="楊錫林 ";
key[2][2]="黃君瑜 ";
key[2][3]="洪福建 ";
key[2][4]="王建忠 ";
key[2][5]="鍾帛煻 ";
key[2][6]="盧小蓉 ";
key[2][7]="詹世宏 ";
key[2][8]="梁培勇 ";
key[3][0]="歐陽梅 ";
key[3][1]="李佩芸 ";
key[3][2]="李玉霞 ";
key[3][3]="李世琛 ";
key[3][4]="山查比杜 ";
key[3][5]="李建逸 ";
key[3][6]="洪偉鈞 ";
key[3][7]="蔡宗燕 ";
key[3][8]="葉華光 ";
key[4][0]="林于鈴 ";
key[4][1]="陳瀅如 ";
key[4][2]="林淑容 ";

function Buildkey(num)
{
document.myForm.fruit.selectedIndex="0;
for(ctr=0;ctr<key[num].length;ctr++){
document.myForm.fruit.options[ctr]=new Option(key[num][ctr],key[num][ctr]);
}
document.myForm.fruit.length=key[num].length;
document.writeln(key[num].length);
}


//-->
</Script>

為什麼第二層總是跑不出來


reply to postreply to post
作者 Re:[問題]即時多層下拉選單 [Re:ㄚ孝]
yulie





發文: 2
積分: 0
於 2006-06-06 13:21 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
原來是我漏了一行
拍謝!!

可是我想請教另一個問題
就是我想重複做'M'個'兩層下拉式選單'
這想成裡面的資料都是一樣的
那我該怎麼做

我有是過用for
可是第二層的值卻沒有辦法回傳


reply to postreply to post
作者 Re:[問題]即時多層下拉選單 [Re:ㄚ孝]
estrelas





發文: 227
積分: 0
於 2006-06-06 18:51 user profilesend a private message to usersend email to estrelasreply 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
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
<script>
 
/**
 *  這裡的值是由JSP產生
 */
var dataSource = {
  { "subject":"應用數學系", "text":"張志豪", "value":"00000001" },
  { "subject":"應用數學系", "text":"王承斌", "value":"00000002" },
  { "subject":"應用數學系", "text":"呂淑鈴", "value":"00000003" },
  { "subject":"物理學系", "text":"陳建宏", "value":"00000004" },
  { "subject":"物理學系", "text":"周秋芬", "value":"00000005" },
  { "subject":"心理學系", "text":"林余昭", "value":"00000006" },
  { "subject":"心理學系", "text":"張德新", "value":"00000007" },
  { "subject":"化學系", "text":"許大偉", "value":"00000008" },
  { "subject":"化學系", "text":"謝俊男", "value":"00000009" },
  { "subject":"化學系", "text":"楊鎮槐", "value":"00000010" }
};
 
function getSelectOption() {
 
  var _selectOne = arguments[0];
  var _filter = arguments[1];
  
  try {
  
    //  先清除 Option
    while( _selectOne["options"]["length"] > 0 ) {
      
      _selectOne.remove(0);
    }
  
    //  過濾加入 Option, 方法由引數傳入
    for( var i = 0; i < dataSource["length"]; i++ ) {
    
      if( _filter( dataSource[i] ) ) {
        
        var _opt = new Option();
        
        for( var f in dataSource[i] ) {
        
          _opt[f] = dataSource[i][f]; 
        }
        
        _selectOne.add(_opt);
      }
    }
  }
  catch (e) {
  
    //
  }
}
 
/**
 *  初始化時...
 */
function init() {
 
  form1["selectSubject"]["onchange"] = function() {
  
    getSelectOption(
      form1["selectStudent"],
      function() {
      
        var _data = arguments[0];
        
        if( form1["selectSubject"]["value"] == _data["subject"] )
          return true;
        else
          return false;
      }
    );
  }
 
}
 
</script>
 


當然前提是資料量不多, 不常變動
要不然的話還是考慮用http Request 吧


reply to postreply to post
tôi yêu gái Việt Nam ^__^
作者 Re:[問題]即時多層下拉選單 [Re:ㄚ孝]
minichitina





發文: 13
積分: 0
於 2007-05-05 16:25 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
各位高手:
您們寫得我照著寫也不知道那裡出問題,還是出不來,以下是我改過的程式,我是要在jsp網頁裏從資料庫取出資料,在html中有兩個下拉式選單,其第二個選單需跟著第一個選單變動而變動,即select id from a where id >= 第一個下拉式選單之值
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
<%
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Connection Conn = DriverManager.getConnection("jdbc:microsoft:sqlserver://140.115.84.223:1433;databasename=project","project","coolmeeting");
 
int i=0;
Statement stmt = Conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
Statement stmt2 = Conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
String SQL = "Select id From a";
ResultSet rs = stmt.executeQuery(SQL);
%>
 
<SCRIPT LANGUAGE="javascript">
<!--
function ChangeSelect(city, region)
{
val = city.options[city.options.selectedIndex].value;
 
  <%while(rs.next()){  
  
  String SQL2 = " select id from a where id >=" +  rs.getString("id") ;  
  ResultSet rs2 = stmt2.executeQuery(SQL2);
  
  %>
  if (val == '<%=rs.getString("id")%>')
  {
    
    <%while(rs2.next()){
    i++;
    }%>
    region.length = <%=i%>; 
    <%
    i=0;
    rs2.first();
    do{%>
    region.options[<%=i%>].value = '<%=rs2.getString("id")%>'; region.options[<%=i%>].text = '<%=rs2.getString("id")%>';
    <%
    i++;
    }while(rs2.next());
    i=0;%>
  }
  <%}
  rs.first();%>
}
-->
</script>
 
<form name="selection">
<select name=city onChange="ChangeSelect(document.selection.city,document.selection.region)" size="1">
                   <option>==請選擇城市==</option>
                   <%do{%>
                   <option value="<%=rs.getString("id")%>"><%=rs.getString("id")%></option>
                   <%}while(rs.next());%>
                   </select><BR>                    
                 選擇您要的區域</font><br>
                   <SELECT name=region>
 
                   </SELECT> </p> 
</form>


browser edited on 2007-05-06 13:15
reply to postreply to post
作者 Re:[問題]即時多層下拉選單 [Re:minichitina]
eidson72





發文: 25
積分: 0
於 2007-05-16 11:48 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
<%@ page language="java" contentType="text/html; charset=UTF-8" import="java.sql.*" pageEncoding="UTF-8"%>
<!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=UTF-8">
<title></title>
</head>
<body>
<%
Class.forName("org.logicalcobwebs.proxool.ProxoolDriver");
Connection Conn = DriverManager.getConnection("proxool.xml-test");

int i=0;
Statement stmt = Conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
Statement stmt2 = Conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
String SQL = "Select * from unit";
ResultSet rs = stmt.executeQuery(SQL);
%>

<SCRIPT LANGUAGE="javascript">
<!--
function ChangeSelect(city, region)
{
val = city.options[city.options.selectedIndex].value;

<%
while(rs.next())
{
String SQL2 = " select * from class where unit="+rs.getString("unit_id");
ResultSet rs2 = stmt2.executeQuery(SQL2);

%>
if (val == '<%=rs.getString("unit")%>')
{

<%while(rs2.next()){
i++;
}%>
region.length = <%=i%>;
<%
i=0;
rs2.first();
do{%>
region.options[<%=i%>].value = '<%=rs2.getString("class")%>';
region.options[<%=i%>].text = '<%=rs2.getString("class")%>';
<%
i++;
}while(rs2.next());
i=0;%>
}
<%}
rs.first();%>
}
-->
</script>

<form name="selection">
<select name=city onChange="ChangeSelect(document.selection.city,document.selection.region)" size="1">
<option>==請選擇城市==</option>
<%do{%>
<option value="<%=rs.getString("unit_id")%>"><%=rs.getString("unit")%></option>
<%}while(rs.next());%>
</select><BR>
選擇您要的區域</font><br>
<SELECT name=region>

</SELECT> </p>
</form>

</body>
</html>

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
請教一下各位大大..我是初學者...我不知道我那邊有錯...><---下面是apache log
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HTTP Status 500 -

--------------------------------------------------------------------------------

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: Exception in JSP: /sql/test.jsp:44

41: i=0;
42: rs2.first();
43: do{%>
44: region.options[<%=i%>].value = '<%=rs2.getString("class")%>';
45: region.options[<%=i%>].text = '<%=rs2.getString("class")%>';
46: <%
47: i++;

Stacktrace:
  org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:506)
  org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
  org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
  org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

root cause

javax.servlet.ServletException: Illegal operation on empty result set.
  org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:843)
  org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:776)
  org.apache.jsp.sql.test_jsp._jspService(test_jsp.java:151)
  org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
  org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:334)
  org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
  org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

root cause

java.sql.SQLException: Illegal operation on empty result set.
  com.mysql.jdbc.ResultSet.checkRowPos(ResultSet.java:4341)
  com.mysql.jdbc.ResultSet.getStringInternal(ResultSet.java:2137)
  com.mysql.jdbc.ResultSet.getString(ResultSet.java:2132)
  com.mysql.jdbc.ResultSet.getString(ResultSet.java:2250)
  org.apache.jsp.sql.test_jsp._jspService(test_jsp.java:100)
  org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
  org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:334)
  org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
  org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

note The full stack trace of the root cause is available in the Apache Tomcat/5.5.20 logs.


reply to postreply to post
作者 Re:[問題]即時多層下拉選單 [Re:ㄚ孝]
alvin0224





發文: 36
積分: 0
於 2007-05-16 14: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
在你的程式碼裡有兩個問題
第一:
在ResultSet 的處理請不要使用 do while loop
因為你的資料庫回傳可能為空的值
但do while 不管怎樣都會做第一次
所以會造成讀取空的ResultSet的錯誤

解決發法請用
while(rs.next()) {

}

第二:
你在之前
while(rs2.next()){
i++;
}
已經把cursor 只到最後一個了
所以當你在do while 時的rs2 已經後面沒有next()
在兩個中間加上
rs2.beforeFirst() ;
應該就可以了~不過還是建議把do while 改成 while


reply to postreply to post
作者 Re:[問題]即時多層下拉選單 [Re:ㄚ孝]
eidson72





發文: 25
積分: 0
於 2007-05-16 15:41 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
謝謝大大的指導,我已經知道了..謝謝...

reply to postreply to post
作者 Re:[問題]即時多層下拉選單 [Re:ㄚ孝]
minichitina





發文: 13
積分: 0
於 2007-05-31 08:33 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
To:eidson72
請問您
region.options[<%=i%>].value = '<%=rs2.getString("class")%>';
region.options[<%=i%>].text = '<%=rs2.getString("class")%>'
這裡的class是欄位名稱是不是?不好意思,我也想做即時多層下拉選單,只是一直解不開


reply to postreply to post
作者 Re:[問題]即時多層下拉選單 [Re:ㄚ孝]
minichitina





發文: 13
積分: 0
於 2007-06-04 08:04 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
int i = 0;
int j = 0;
Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
  Statement stmt2 = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
  Statement stmt3 = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);

  String SQL = "Select * from unit";
  ResultSet rs = stmt.executeQuery(SQL);
  %>

<SCRIPT LANGUAGE="javascript">
<!--
function ChangeSelect(city, region ,rd)
{
val = city.options[city.options.selectedIndex].value;
val2 = region.options[region.options.selectedIndex].value;
<%
while(rs.next())
{
String SQL2 = " select * from class where unit="+rs.getString("unit_id");
ResultSet rs2 = stmt2.executeQuery(SQL2);

%>
if (val == '<%=rs.getString("unit_id")%>')
{

<%
while(rs2.next()){
i++;
}
%>
region.length = <%=i%>;
<%
i=0;
rs2.beforeFirst() ;
while(rs2.next()){%>
region.options[<%=i%>].value = '<%=rs2.getString("class")%>';
region.options[<%=i%>].text = '<%=rs2.getString("class")%>';
<%
i++;
}
i=0;%>
}
<%
while(rs2.next())
  {
     String SQL3 = " select * from road where u_id="+rs.getString("unit_id") + " and c_id="+rs2.getString("class_id");
     ResultSet rs3 = stmt3.executeQuery(SQL3);
%>
if (val == '<%=rs.getString("unit_id")%>' && val2 == '<%=rs2.getString("class_id")%>')
{
<%
while(rs3.next()){
  j++;
  }

%>
rd.length = <%=j%>;
<%
j=0;
rs3.beforeFirst() ;
while(rs3.next()){%>
rd.options[<%=j%>].value = '<%=rs3.getString("read")%>';
rd.options[<%=j%>].text = '<%=rs3.getString("read")%>';
<%
j++;
} j=0;%>
}
<%}
rs2.first();
}
rs.first();%>
}
-->
</script>
<form name="selection">
<select name=city onChange="ChangeSelect(document.selection.city,document.selection.region,document.selection.rd)" size="1">
<option>==請選擇城市==</option>
<%do{%>
<option value="<%=rs.getString("unit_id")%>"><%=rs.getString("unit")%></option>
<%}while(rs.next());%>
</select><BR>
請選擇區域<br>
<SELECT name=region>

</SELECT>
<BR>
請選擇道路<br>
<SELECT name=rd>

</SELECT>
</form>

</body>
</html>
-----------------------------------------------------------------------------------------------------
請問各位前輩,我那裡有錯,怎麼只有城市的下拉式選單可以出來,再來的區域就出不來了?拜託各位前輩指導。感謝!


reply to postreply to post
作者 Re:[問題]即時多層下拉選單 [Re:ㄚ孝]
minichitina





發文: 13
積分: 0
於 2007-06-07 08:00 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
int i = 0;
int j = 0;
Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
  Statement stmt2 = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
  Statement stmt3 = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);

  String SQL = "Select * from unit";
  ResultSet rs = stmt.executeQuery(SQL);
  ResultSet rs2 = null;
  ResultSet rs3 = null;
  %>

<SCRIPT LANGUAGE="javascript">
<!--
function ChangeSelect(city, region ,rd)
{
val = city.options[city.options.selectedIndex].value;
val2 = region.options[region.options.selectedIndex].value;

<%
//rs while begin
while(rs.next())
{
String SQL2 = " select * from class where unit="+rs.getString("unit_id");
rs2 = stmt2.executeQuery(SQL2);

%>
if (val == '<%=rs.getString("unit_id")%>')
{

<%
// rs2 while begin
while(rs2.next()){
i++;
}
//rs2 while end
%>
region.length = <%=i%>;
<%
i=0;
rs2.beforeFirst() ;
//show rs2 while begin
while(rs2.next()){%>
region.options[<%=i%>].value = '<%=rs2.getString("class")%>';
region.options[<%=i%>].text = '<%=rs2.getString("class")%>';
<%
i++;
}
//show rs2 while end
i=0;%>
}
<%
while(rs2.next())
  {
     String SQL3 = " select * from road where u_id="+rs.getString("unit_id") + " and c_id="+rs2.getString("class_id");
     rs3 = stmt3.executeQuery(SQL3);
%>
if (val == '<%=rs.getString("unit_id")%>' && val2 == '<%=rs2.getString("class_id")%>')
{
<%
while(rs3.next()){
  j++;
  }

%>
rd.length = <%=j%>;
<%
j=0;
rs3.beforeFirst() ;
//show rs2 while begin
while(rs3.next()){%>
rd.options[<%=j%>].value = '<%=rs3.getString("road")%>';
rd.options[<%=j%>].text = '<%=rs3.getString("road")%>';
<%
j++;
}
//show rs2 while end
j=0;%>
}
<%}
rs2.first();
}
rs.first();%>
}
-->
</script>

<form name="selection">
<select name=city onChange="ChangeSelect(document.selection.city,document.selection.region,document.selection.rd)" size="1">
<option>==請選擇城市==</option>
<%do{%>
<option value="<%=rs.getString("unit_id")%>"><%=rs.getString("unit")%></option>
<%}while(rs.next());%>
</select><BR>
<br>
<SELECT name=region onChange="ChangeSelect(document.selection.city,document.selection.region,document.selection.rd)" size="1">
<option>==選擇區域==</option>
<%do{ %>
<option value="<%=rs2.getString("class_id") %>"><%=rs2.getString("class") %></option>
<%}while(rs2.next()); %>
</SELECT>
<BR>
<br>
<SELECT name=rd>

==選擇路==

</SELECT>
</form>
----------------------------------------------------------------------------------------------------
請問各位前輩,我要修改那裡才能讓我可以選擇到路


reply to postreply to post
作者 Re:[問題]即時多層下拉選單 [Re:alanting]
catte





發文: 34
積分: 0
於 2011-06-27 04:33 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
大大我有個問題 那就是city的SQL Server的資料表要怎麼設才能讓依照國家不同,而找到想要城市~~

reply to postreply to post
作者 Re:[問題]即時多層下拉選單 [Re:minichitina]
catte





發文: 34
積分: 0
於 2011-06-27 14:44 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
minichitina wrote:
各位高手:
您們寫得我照著寫也不知道那裡出問題,還是出不來,以下是我改過的程式,我是要在jsp網頁裏從資料庫取出資料,在html中有兩個下拉式選單,其第二個選單需跟著第一個選單變動而變動,即select id from a where id >= 第一個下拉式選單之值
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
<%
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
Connection Conn = DriverManager.getConnection("jdbc:microsoft:sqlserver://140.115.84.223:1433;databasename=project","project","coolmeeting");
 
int i=0;
Statement stmt = Conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
Statement stmt2 = Conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
String SQL = "Select id From a";
ResultSet rs = stmt.executeQuery(SQL);
%>
 
<SCRIPT LANGUAGE="javascript">
<!--
function ChangeSelect(city, region)
{
val = city.options[city.options.selectedIndex].value;
 
  <%while(rs.next()){  
  
  String SQL2 = " select id from a where id >=" +  rs.getString("id") ;  
  ResultSet rs2 = stmt2.executeQuery(SQL2);
  
  %>
  if (val == '<%=rs.getString("id")%>')
  {
    
    <%while(rs2.next()){
    i++;
    }%>
    region.length = <%=i%>; 
    <%
    i=0;
    rs2.first();
    do{%>
    region.options[<%=i%>].value = '<%=rs2.getString("id")%>'; region.options[<%=i%>].text = '<%=rs2.getString("id")%>';
    <%
    i++;
    }while(rs2.next());
    i=0;%>
  }
  <%}
  rs.first();%>
}
-->
</script>
 
<form name="selection">
<select name=city onChange="ChangeSelect(document.selection.city,document.selection.region)" size="1">
                   <option>==請選擇城市==</option>
                   <%do{%>
                   <option value="<%=rs.getString("id")%>"><%=rs.getString("id")%></option>
                   <%}while(rs.next());%>
                   </select><BR>                    
                 選擇您要的區域</font><br>
                   <SELECT name=region>
 
                   </SELECT> </p> 
</form>



我想問一下大大這個city和region分別是代表什麼??資料表嗎??


reply to postreply to post
作者 Re:[問題]即時多層下拉選單 [Re:catte]
bernardvai





發文: 491
積分: 0
於 2011-06-27 16:56 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
請先分清楚 JSP 及 javascript 的次序與關係.

你這樣寫, 會好亂, 好難 debug.


reply to postreply to post
作者 Re:[問題]即時多層下拉選單 [Re:ㄚ孝]
catte





發文: 34
積分: 0
於 2011-06-28 03:14 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
這是我依造前面的高手做的程式
但是第一個下拉是選到什麼,第二個都是出現一樣
請問各位高手要怎麼修該??
如果可以的話可以講一下資料那邊要怎麼設

<%@ page import="java.sql.*" %>
<%@page import="java.io.* "%>
<%@ page contentType="text/html;charset=Big5" %>
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=big5">
<title>Test</title>
</head>

<body>
<%
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
Connection Conn = DriverManager.getConnection("jdbc:sqlserver://192.168.31.51:1433;databaseName=bpp","sa","12345");

int i=0;
Statement stmt=Conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
Statement stmt2=Conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String SQL = "Select id From a";
ResultSet rs = stmt.executeQuery(SQL);
%>

<SCRIPT LANGUAGE="javascript">
<!--
function ChangeSelect(city, region)
{
val = city.options[city.options.selectedIndex].value;

<%while(rs.next()){

String SQL2 = " select * from city " + rs.getString("id") ;
ResultSet rs2 = stmt2.executeQuery(SQL2);

%>
if (val == '<%=rs.getString("id")%>')
{

<%while(rs2.next()){
i++;
}%>
region.length = <%=i%>;
<%
i=0;
rs2.first();
do{%>
region.options[<%=i%>].value = '<%=rs2.getString("aa")%>';
region.options[<%=i%>].text = '<%=rs2.getString("aa")%>';
<%
i++;
}while(rs2.next());
i=0;%>

}
<%}
rs.first();%>
}
-->
</script>

<form name="selection">
<select name=city onChange="ChangeSelect(document.selection.city,document.selection.region)" size="1">
<option>==請選擇城市==</option>
<%do{%>
<option value="<%=rs.getString("id")%>"><%=rs.getString("id")%></option>
<%}while(rs.next());%>
</select><BR>
選擇您要的區域</font><br>
<SELECT name=region>

</SELECT> </p>
</form>


reply to postreply to post
作者 Re:[問題]即時多層下拉選單 [Re:catte]
bernardvai





發文: 491
積分: 0
於 2011-06-28 09: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
請貼出你在 browser 所見到的原始檔.

在ie, View --> Source
Firefox, 檢視 --> 頁面原始碼.

這個才可以較易幫你看看 javascript 出了什麼問題.

依我按你的程式估計, 你得到的原始檔. 會是以下這樣, 是可以運行的.
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
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=big5">
<title>Test</title>
</head>
 
<body>
<SCRIPT LANGUAGE="javascript">
function ChangeSelect(city, region){
  val = city.options[city.options.selectedIndex].value;
  if (val == 'a'){
     region.length=2;
     region.options[0].value= 'x';
     region.options[0].text=  'x';
     region.options[1].value= 'y';
     region.options[1].text=  'y';
  }
  if (val == 'b'){
     region.length=3;
     region.options[0].value= 't';
     region.options[0].text=  't';
     region.options[1].value= 'u';
     region.options[1].text=  'u';
     region.options[2].value= 'v';
     region.options[2].text=  'v';   
  }
}
 
</script>
 
<form name="selection">
<select name=city onChange="ChangeSelect(document.selection.city,document.selection.region)" size="1">
<option>==請選擇城市==</option>
<option value="a">a</option>
<option value="b">b</option>
</select><BR>
選擇您要的區域</font><br>
<SELECT name=region>
 
</SELECT> </p>
</form> 


bernardvai edited on 2011-06-28 10:13
reply to postreply to post
作者 Re:[問題]即時多層下拉選單 [Re:bernardvai]
catte





發文: 34
積分: 0
於 2011-06-28 11:36 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
這是我程式的原始碼
還有我的資料表(city)的設定
這樣看好像是我資料表的問題,不知道是不是這樣
請大大幫忙一下~~
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=big5">
<title>Test</title>
</head>

<body>


<SCRIPT LANGUAGE="javascript">
<!--
function ChangeSelect(city, region)
{
val = city.options[city.options.selectedIndex].value;


if (val == '台北 ')
{


region.length = 4;

region.options[0].value = '麥當勞 ';
region.options[0].text = '麥當勞 ';

region.options[1].value = '肯德基 ';
region.options[1].text = '肯德基 ';

region.options[2].value = ' ';
region.options[2].text = ' ';

region.options[3].value = ' ';
region.options[3].text = ' ';


}

if (val == '台中 ')
{


region.length = 4;

region.options[0].value = '麥當勞 ';
region.options[0].text = '麥當勞 ';

region.options[1].value = '肯德基 ';
region.options[1].text = '肯德基 ';

region.options[2].value = ' ';
region.options[2].text = ' ';

region.options[3].value = ' ';
region.options[3].text = ' ';


}

if (val == '台南 ')
{


region.length = 4;

region.options[0].value = '麥當勞 ';
region.options[0].text = '麥當勞 ';

region.options[1].value = '肯德基 ';
region.options[1].text = '肯德基 ';

region.options[2].value = ' ';
region.options[2].text = ' ';

region.options[3].value = ' ';
region.options[3].text = ' ';


}

if (val == '高雄 ')
{


region.length = 4;

region.options[0].value = '麥當勞 ';
region.options[0].text = '麥當勞 ';

region.options[1].value = '肯德基 ';
region.options[1].text = '肯德基 ';

region.options[2].value = ' ';
region.options[2].text = ' ';

region.options[3].value = ' ';
region.options[3].text = ' ';


}

}
-->
</script>

<form name="selection">
<select name=city onChange="ChangeSelect(document.selection.city,document.selection.region)" size="1">
<option>==請選擇城市==</option>

<option value="台北 ">台北 </option>

<option value="台中 ">台中 </option>

<option value="台南 ">台南 </option>

<option value="高雄 ">高雄 </option>

</select><BR>
選擇您要的區域</font><br>
<SELECT name=region>

</SELECT> </p>
</form>


reply to postreply to post
作者 Re:[問題]即時多層下拉選單 [Re:catte]
bernardvai





發文: 491
積分: 0
於 2011-06-28 14:21 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
17
18
19
20
21
22
23
24
25
26
27
28
29
30
javascript 在生出來的原始檔正常運作.
===========================================================
已找到問題是在SQL 
String SQL = "Select id From a";
String SQL2 = " select * from city " + rs.getString("id");
 
Table a  沒有問題.
id
=====
台北 
台中 
台南 
高雄 
 
Table city 應要只有 2 欄
id       aa
===  ==========
台北  麥當勞
台北  肯德基 
台中  貴族世家
台南  小廣東
....  ....
....  ....
 
SQL2 應改為
String SQL2 = " select * from city where id='" + rs.getString("id") + "'";
 
(得出來的sql 會有如 : select *  from city where id='台北 ';)
 
有留意你的城市名後會有多一個空格, 是有意的嗎 ?


bernardvai edited on 2011-06-28 14:23
reply to postreply to post
go to first page go to previous page  1   2   3  go to next page go to last page
» JWorld@TW »  Servlet/JSP 討論區

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

JWorld@TW 本站商標資訊

Powered by Powerful JuteForum® Version Jute 1.5.8