idd=request.getParameter("country_select")
idd有可能为空,要不你把那个SQL语句打出来看看

解决方案 »

  1.   

    onChange里面的是javascript脚本,你脚本在哪?
    String idd=request.getParameter("country_select");
    request得到的是从上一次访问页里面传过来的值,你选择省份之后页面也没有刷新过,如果得到country_select.
    还有你省份列表的那个sql语句后面没where子句的?这样列出来的不是全部数据吗?
      

  2.   

    源程序为:
    <%@ page contentType="text/html;charset=GBK" import="java.sql.*" %>
    <%@ include file="include/check.js.jsp"%>
    <jsp:useBean id="mdb" class="china.db.faq" scope="page"/>
    <%
    ResultSet rs;
    String sql="select * from area where pid='0'";
    rs=mdb.executeQuery(sql);
    %>
    <html>
    <form>
        <table>
            <select name="country_select"  onChange="fill_state()">
            <option value="0">省份</option>
         <%
       while(rs.next()){
       String name=null;
       int id=0;
       name=rs.getString("name");
       id=rs.getInt("id");
       out.println("<option value="+id+">"+name+"</option>");
       }
     %>  
            </select> 
            <select name="state_select" onChange="fill_city()">
            <option value="0">城市</option>
    <%
    String idd=request.getParameter("country_select");
    String sql1="select * from area where pid="+idd+" ";
    rs=mdb.executeQuery(sql1);
    while(rs.next()){
      int id=0;
      String name=null;
      id=rs.getInt("id");
      name=rs.getString("name");
      out.println("<option value="+id+">"+name+"</option>");
    }%>
        </table>
    </form>
    </html>
    还有:fill_state() 在 check.js.jsp 中如下
      function fill_state(){//写入地级市数据
    frm.state_select.options.length=1;
    frm.city_select.options.length=1;
    for (var i=0;i<=Arr.length-1;i++){
    if ((frm.country_select.options[frm.country_select.selectedIndex].value!=0)&&(Arr[i].pid==frm.country_select.options[frm.country_select.selectedIndex].value))
      {
    frm.state_select.options.length+=1;
    frm.state_select.options[frm.state_select.options.length-1].text=Arr[i].name;
    frm.state_select.options[frm.state_select.options.length-1].value=Arr[i].id;
       
     }
       }
        }