複数選択ドロップダウン値を JSP PAGE に送信しています。以下は、複数選択値を送信する AJAX コードです。JSP ページには、データベースから読み取り、その値を別のドロップダウンに表示するための SQL クエリが含まれています。以下のコードは、複数選択ではなく選択に基づいてカスケード ドロップダウン値のみを表示します。すべての値ではなく、1 つの値のみが apps.jsp に送信されているようです。いくつかの変更を試みましたが、うまくいきませんでした。以下は、私が利用できる最高の作業コードです。最初のドロップダウンからの複数選択に基づいて、2 番目のドロップダウン表示値を取得する方法はありますか? 単一のドロップダウンは、以下のコードで正常に機能します。ありがとうございました。
<select multiple="multiple" name="RequirementFor" id="RequirementFor" onchange="showState(this.value);">
<option value="1">Test1</option>
<option value="2">Test2</option>
<option value="3">Test3</option>
<option value="4">Test4</option>
</select>
<div id="plat"><select name="Platform" id="Platform" multiple="multiple" onchange='showState2(this.value)'>
</select></div>
//AJAX Code
var xmlHttp ;
var xmlHttp;
function showState(str){
if (typeof XMLHttpRequest != "undefined"){
xmlHttp= new XMLHttpRequest();
}
else if (window.ActiveXObject){
xmlHttp= new ActiveXObject("Microsoft.XMLHTTP");
}
if (xmlHttp==null){
alert("Browser does not support XMLHTTP Request");
return;
}
var url="apps.jsp";
url +="?value=" +str;
xmlHttp.onreadystatechange = stateChange;
xmlHttp.open("GET", url, true);
xmlHttp.send(null);
}
function stateChange(){
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
document.getElementById("plat").innerHTML=xmlHttp.responseText ;
}
}
以下は、JSP クエリ (apps.jsp) ページのコードです。
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance();
Connection con = DriverManager.getConnection("jdbc:sqlserver://localhost", "username", "password");
Statement stmt;
ResultSet rs;
String[] funID= request.getParameterValues("value");
String conCat = "";
try{
if(funID.length>0)
{
for(int i=0;i<funID.length; i++)
{
conCat = funID[i] +" "+ "OR" + " "+ "FU_DEPARTMENT_ID= " + conCat;
}
conCat = conCat.substring(0, conCat.length() - 22);
}
}
catch(Exception e)
{out.println(e);}
String buffer="<select name='state' multiple='multiple'><option value='-1'>Select</option>";
try
{
String sqlSelect1="Select FU_ID, FU_NAME from UNIT where FU_DEPARTMENT_ID ="+conCat+" ORDER BY FU_NAME ASC";
stmt = con.createStatement();
rs = stmt.executeQuery(sqlSelect1);
while(rs.next()){
buffer=buffer+"<option value='"+rs.getString("FU_ID")+"'>"+rs.getString("FU_NAME")+"</option>";
}
buffer=buffer+"</select>";
response.getWriter().println(buffer);
stmt.close();
rs.close();
con.close();
}
catch(Exception e){
System.out.println(e);
}