2013-01-23 100 views
0

我嘗試填充下拉菜單。第二個和第三個下拉列表應顯示從數據庫檢索後按照上一個下拉值選擇的值。可以選擇任何一個指出我的代碼中的錯誤。當我運行代碼時,我不能在任何下拉列表中選擇任何值。 Plz幫助我。
Country.jsp從jsp中的數據庫動態下拉不起作用

State.jsp

City.jsp幾乎是一樣的state.jsp

我在數據庫中已經添加值。在此先感謝

回答

0

請使用預定義的框架,如JSTL/SQL和jquery.js和

這應該工作:

<%-- 
    Document : index 
    Created on : Jan 23, 2013, 7:43:24 PM 
    Author  : Ankit 
--%> 

<%@taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%> 
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 
<%@page contentType="text/html" pageEncoding="UTF-8"%> 
<%@page import="java.sql.*"%> 
<sql:setDataSource driver="oracle.jdbc.driver.OracleDriver" url="jdbc:oracle:thin:@localhost:1521:XE" user="system" password="ankit" var="db" scope="request" /> 
<sql:query dataSource="${db}" var="countrys" sql="SELECT * FROM country" /> 
<sql:query dataSource="${db}" var="states" sql="SELECT * FROM state WHERE countryid=${param['countryid']}" /> 
<sql:query dataSource="${db}" var="cities" sql="SELECT * FROM city WHERE cityid=${param['cityid']}" /> 
<!DOCTYPE html> 
<html> 
    <head> 
     <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8"> 
     <META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE"> 
     <script type="text/javascript" language="javascript" src="jquery.js"></script> 
    </head> 
    <body> 
     <form> 
     <select name="countryid" id="countrylist" onclick="jQuery('#statelist').load('?countryid='+jQuery(this).val(),'#statelist');"> 
      <c:forEach items="${countrys}" var="country"> 
       <option value="${country.id}">${country.name}</option> 
      </c:forEach> 
     </select> 
     <select name="stateid" id="statelist" onclick="jQuery('#citylist').load('?cityid='+jQuery(this).val(),'#citylist');"> 
      <c:forEach items="${states}" var="state"> 
       <option value="${state.id}">${state.name}</option> 
      </c:forEach> 
     </select> 
     <select name="cityid" id="citylist"> 
      <c:forEach items="${cities}" var="city"> 
       <option value="${city.id}">${city.name}</option> 
      </c:forEach> 
     </select> 
     <button>Finish</button> 
     </form> 
    </body> 
</html> 
相關問題