| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1904 人关注过本帖
标题:ajax二级联动+读取数据库的值在页面显示
取消只看楼主 加入收藏
xiaoqjwt
Rank: 1
等 级:新手上路
帖 子:5
专家分:8
注 册:2011-4-14
结帖率:0
收藏
 问题点数:0 回复次数:0 
ajax二级联动+读取数据库的值在页面显示
我在一个jsp中显示一个二级联动可以,为什么不能显示两个二级联动,附jsp代码和sevlet代码
jsp代码:
<%@page import="java.util.Map"%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.util.List"%>
<%@page import="java.sql.Driver"%>
<%@page import="java.sql.Connection"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.SQLException"%>
<%@page import="java.util.HashMap"%>


<%@ page language="java" contentType="text/html; utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>烟草查询</title>
</head>
<script type="text/javascript">
  function cityChange(objVal){
      createcityXMLHttpRequest();
      document.getElementById("town").length=1;
      xmlHttp.onreadystatechange=townList;
      var url="/chaxun1/ChaxunServlet?city="+objVal;
      xmlHttp.open("GET",url,true);
      xmlHttp.send(null);
      }
  function typeChange(objVal){
      createtypeXMLHttpRequest();
      document.getElementById("lever").length=1;
      xmlHttp.onreadystatechange=leverList;
      var url="/chaxun1/ChaxunServlet?type="+objVal;
      xmlHttp.open("GET",url,true);
      xmlHttp.send(null);
      }
  
      
      var xmlHttp=false;
      function createcityXMLHttpRequest(){
      if(window.ActiveXObject){
      try{
        xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
        }catch(e){
        try{
        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }catch(e){
        window.alert("创建XMLHttpRequest对象错误"+e);
        }
        }
        }else if(window.XMLHttpRequest){
        xmlHttp=new XMLHttpRequest();
        }
        if(!(xmlHttp)){
           widow.alert("创建XMLHttpRequest对象异常!");
           }
         }
         function townList(){
         if(xmlHttp.readyState==4){
         if(xmlHttp.status==200){
         parsecityXML(xmlHttp.responseXML);
         }
        }
       }
         
         var xmlHttp=false;
         function createtypeXMLHttpRequest(){
         if(window.ActiveXObject){
         try{
           xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
           }catch(e){
           try{
           xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
           }catch(e){
           window.alert("创建XMLHttpRequest对象错误"+e);
           }
           }
           }else if(window.XMLHttpRequest){
           xmlHttp=new XMLHttpRequest();
           }
           if(!(xmlHttp)){
              widow.alert("创建XMLHttpRequest对象异常!");
              }
            }
            function leverList(){
            if(xmlHttp.readyState==4){
            if(xmlHttp.status==200){
            parsetypeXML(xmlHttp.responseXML);
            }
           }
          }
       function parsecityXML(xmlDoc){
           var citylen=xmlDoc.getElementsByTagName("town");
           var _townSel=document.getElementById("town");
           for(var i=0;i<citylen.length;i++){
               var opt=document.createElement("OPTION");
               opt.text=xmlDoc.getElementsByTagName("town")[i].firstChild.data;
               opt.value=xmlDoc.getElementsByTagName("town")[i].firstChild.data;
               _townSel.add(opt);
           }
       }
       function parsetypeXML(xmlDoc){
              var typelen=xmlDoc.getElementsByTagName("lever");
              var _leverSel=document.getElementById("lever");
              for(var i=0;i<typelen.length;i++){
                  var opt=document.createElement("OPTION");
                  opt.text=xmlDoc.getElementsByTagName("lever")[i].firstChild.data;
                  opt.value=xmlDoc.getElementsByTagName("lever")[i].firstChild.data;
                  _leverSel.add(opt);
              }
          }

       </script>
<body>
<%
    response.setContentType("text/html");
    request.setCharacterEncoding("utf-8");
    response.setCharacterEncoding("utf-8");

    Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance();
    String url = "jdbc:sqlserver://localhost:1433;databaseName=TLQ_Query";
    Connection conn = DriverManager.getConnection(url, "sa", "");
    Statement stmt = conn.createStatement();
    //ResultSet rs = stmt.executeQuery(sql);
    List list = new ArrayList();
   
    String style = request.getParameter("style");
    String year = request.getParameter("year");
    String city = request.getParameter("city");
    String town = request.getParameter("town");
    String type = request.getParameter("type");
    String pz = request.getParameter("pz");
    String lever = request.getParameter("lever");
   
   
    request.setAttribute("style",style);
    request.setAttribute("year",year);
    request.setAttribute("city",city);
    request.setAttribute("town",town);
    request.setAttribute("type",type);
    request.setAttribute("pz",pz);
    request.setAttribute("lever",lever);
   
    if(style == null){
        style = "";
    }
    if(year == null){
        year = "";
    }
    if(city == null){
        city = "";
    }
    if(town == null){
        town = "";
    }
    if(type == null){
        type = "";
    }
    if(pz == null){
        city = "";
    }
    if(lever == null){
        lever = "";
    }
    String sql = "";
    if(style.equals("感官质量")){
        sql = "select  [City],[Year],[O_Place] ,[Lever] ,[T_Type],[A_Qulity],[A_Quantity] ,[Mixedgas] ,[Irrit] ,[Aftaste],[Fla],[Gray] ,[O_Score],[Concen],[Strength] ,[Avail],[Flavor] FROM S_Qulity where 1=1 ";
        if(!year.equals("请选择")){
            sql=sql+" and Year='"+year+"'";
        }
        if(!city.equals("请选择")){
            sql=sql+" and City='"+city+"'";
        }
        if(!town.equals("请选择")){
            sql=sql+" and O_Place='"+town+"'";
        }
        if(!type.equals("请选择")){
            sql=sql+" and T_Type='"+type+"'";
        }
        if(!lever.equals("请选择")){
            sql=sql+" and Lever='"+lever+"'";
        }

        ResultSet rs = stmt.executeQuery(sql);
        while (rs.next()) {
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("City", rs.getString(1));
            map.put("Year", rs.getString(2));
            map.put("O_Place", rs.getString(3));
            map.put("Lever", rs.getString(4));
            map.put("T_Type", rs.getString(5));
            map.put("A_Qulity", rs.getFloat(6));
            map.put("A_Quantity", rs.getFloat(7));
            map.put("Mixedgas", rs.getFloat(8));
            map.put("Irrit", rs.getFloat(9));
            map.put("Aftaste", rs.getFloat(10));
            map.put("Fla", rs.getFloat(11));
            map.put("Gray", rs.getFloat(12));
            map.put("O_Score", rs.getFloat(13));
            map.put("Concen", rs.getFloat(14));
            map.put("Strength", rs.getFloat(15));
            map.put("Avail", rs.getFloat(16));
            map.put("Flavor", rs.getFloat(17));
            
            list.add(map);
        }
        rs.close();
        stmt.close();
        conn.close();
        
    }else if(style.equals("化学成分")){
    sql = "SELECT [City],[Year],[O_Place],[Lever],[T_Type],[T_B_Per],[T_S_Per],[S_Per],[N_Per],[K_Per],[Cl_Per],[N_Base],[S_Base],[Dif_Sugar],[K_Cl] FROM C_Composition where 1=1 ";
    if(!year.equals("请选择")){
        sql=sql+" and Year='"+year+"'";
    }
    if(!city.equals("请选择")){
        sql=sql+" and City='"+city+"'";
    }
    if(!town.equals("请选择")){
        sql=sql+" and O_Place='"+town+"'";
    }
    if(!type.equals("请选择")){
        sql=sql+" and T_Type='"+type+"'";
    }
    if(!lever.equals("请选择")){
        sql=sql+" and Lever='"+lever+"'";
    }
    ResultSet rs = stmt.executeQuery(sql);
    while (rs.next()) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("City", rs.getString(1));
        map.put("Year", rs.getString(2));
        map.put("O_Place", rs.getString(3));
        map.put("Lever", rs.getString(4));
        map.put("T_Type", rs.getString(5));
        map.put("T_B_Per", rs.getFloat(6));
        map.put("T_S_Per", rs.getFloat(7));
        map.put("S_Per", rs.getFloat(8));
        map.put("N_Per", rs.getFloat(9));
        map.put("K_Per", rs.getFloat(10));
        map.put("Cl_Per", rs.getFloat(11));
        map.put("N_Base", rs.getFloat(12));
        map.put("S_Base", rs.getFloat(13));
        map.put("Dif_Sugar", rs.getFloat(14));
        map.put("K_Cl", rs.getFloat(15));
   
        
        list.add(map);
    }
    rs.close();
    stmt.close();
    conn.close();
        
    }else if(style.equals("外观质量")){
        sql="SELECT [City],[Year],[O_Place],[Lever],[T_Type],[Color],[C_Score],[Mat],[M_Score],[Lf_Struct],[L_S_Score],[Id],[Id_Score],[Oil],[OilScore],[C_Inten],[C_I_Score],[Luster],[L_Score],[Leaf],[Lf_Score],[Flex],[Width(cm)],[Length(cm)],[Uni_Per],[O_Score],[Remarks] FROM A_Qulity where 1=1 ";
        if(!year.equals("请选择")){
            sql=sql+" and Year='"+year+"'";
        }
        if(!city.equals("请选择")){
            sql=sql+" and City='"+city+"'";
        }
        if(!town.equals("请选择")){
            sql=sql+" and O_Place='"+town+"'";
        }
        if(!type.equals("请选择")){
            sql=sql+" and T_Type='"+type+"'";
        }
        if(!lever.equals("请选择")){
            sql=sql+" and Lever='"+lever+"'";
        }
        ResultSet rs = stmt.executeQuery(sql);
        while (rs.next()) {
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("City", rs.getString(1));
            map.put("Year", rs.getString(2));
            map.put("O_Place", rs.getString(3));
            map.put("Lever", rs.getString(4));
            map.put("T_Type", rs.getString(5));
            map.put("Color", rs.getString(6));
            map.put("C_Score", rs.getFloat(7));
            map.put("Mat", rs.getString(8));
            map.put("M_Score", rs.getFloat(9));
            map.put("Lf_Struct", rs.getString(10));
            map.put("L_S_Score", rs.getFloat(11));
            map.put("Id", rs.getString(12));
            map.put("Id_Score", rs.getFloat(13));
            map.put("Oil", rs.getString(14));
            map.put("OilScore", rs.getFloat(15));
            map.put("C_Inten", rs.getString(16));
            map.put("C_I_Score", rs.getFloat(17));
            map.put("Luster", rs.getString(18));
            map.put("L_Score", rs.getFloat(19));
            map.put("Leaf", rs.getString(20));
            map.put("Lf_Score", rs.getFloat(21));
            map.put("Flex", rs.getFloat(22));
            map.put("[Width(cm)]", rs.getFloat(23));
            map.put("[Length(cm)]", rs.getString(24));
            map.put("Uni_Per", rs.getFloat(25));
            map.put("O_Score", rs.getFloat(26));
            map.put("Remarks", rs.getString(27));
            
        
            
            list.add(map);
        }
        rs.close();
        stmt.close();
        conn.close();
        
    }else if(style.equals("物理性状")){
        sql = "SELECT [City],[Year][O_Place],[Lever],[T_Type],[Lf_Wight(g)],[S_R_Per],[Hy_Per],[Fil(cm&sup3;/g)],[Lf_Thick] FROM P_Properties where 1=1 ";
        if(!year.equals("请选择")){
            sql=sql+" and Year='"+year+"'";
        }
        if(!city.equals("请选择")){
            sql=sql+" and City='"+city+"'";
        }
        if(!town.equals("请选择")){
            sql=sql+" and O_Place='"+town+"'";
        }
        if(!type.equals("请选择")){
            sql=sql+" and T_Type='"+type+"'";
        }
        if(!lever.equals("请选择")){
            sql=sql+" and Lever='"+lever+"'";
        }
        ResultSet rs = stmt.executeQuery(sql);
        while (rs.next()) {
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("City", rs.getString(1));
            map.put("Year", rs.getString(2));
            map.put("O_Place", rs.getString(3));
            map.put("Lever", rs.getString(4));
            map.put("T_Type", rs.getString(5));
            map.put("Lf_Wight(g)", rs.getFloat(6));
            map.put("S_R_Per", rs.getFloat(7));
            map.put("Hy_Per", rs.getFloat(8));
            map.put("Fil(cm&sup3;/g)", rs.getFloat(9));
            map.put("Lf_Thick", rs.getFloat(10));

        
            
            list.add(map);
        }
        rs.close();
        stmt.close();
        conn.close();        
        
    }
   
%>
<form action="cha.jsp" method="post">
<div
    style="width: 100%; float: left; height: 35px; line-height: 30px; text-align: center; padding-left: 10px; background-image: url(images/bg_01.gif); color: #D67900; font-size: 16px; font-weight: bold;">烟叶主要成分数据分析库</div>
<table border="0" cellpadding="0" cellspacing="0" class="table-01">
    <tr>
        <td>查询条件:</td>
        <td>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp查询类型:</td>
        <td><label> <select name="style" id="style">
            <option value=请选择 ${ forTable== "请选择"?'selected="selected"':'' }>--请选择--</option>
            <option value=感官质量 ${ forTable== "感官质量"?'selected="selected"':'' }>感官质量</otion>
            <option value=化学成分 ${ forTable== "化学成分"?'selected="selected"':'' }>化学成分</option>
            <option value=外观质量 ${ forTable== "外观质量"?'selected="selected"':'' }>外观质量</option>
            <option value=物理性状 ${ forTable== "物理性状"?'selected="selected"':'' }>物理性状</option>
        </select> </label></td>
        <td>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp年份:</td>
        <td><select name="year" id="year">
            <option value=请选择 ${ year== "请选择"?'selected="selected"':'' }>--请选择--</option>
            <option value=2006 ${ year== "2006"?'selected="selected"':'' }>2006</option>
            <option value=2007 ${ year== "2007"?'selected="selected"':'' }>2007</option>
            <option value=2008 ${ year== "2008"?'selected="selected"':'' }>2008</option>
            <option value=2009 ${ year== "2009"?'selected="selected"':'' }>2009</option>
        </select></td>
    </tr>
    <tr>
        <td>地&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp域:</td>
        <td>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp市/州:</td>
        <td><select name="city" id="city"
            onchange="cityChange(this.value);">
            <option value=请选择 ${ city== "请选择"?'selected="selected"':'' }>--请选择--</option>
            <option value=恩施 ${ city== "恩施"?'selected="selected"':'' }>恩施</option>
            <option value=十堰 ${ city== "十堰"?'selected="selected"':'' }>十堰</option>
            <option value=宜昌 ${ city== "宜昌"?'selected="selected"':'' }>宜昌</option>
            <option value=襄樊 ${ city== "襄樊"?'selected="selected"':'' }>襄樊</option>
        </select></td>
        <td>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp县:</td>
        <td><select name="town" id="town">
            <option value=请选择 ${ town== "请选择"?'selected="selected"':'' }>--请选择--</option>
        </select></td>
    </tr>
    <tr>
        <td>类&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp别:</td>
        <td>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp烟叶类型:</td>
        <td><select name="type" id="type" onchange="typeChange(this.value);">
            <option value=请选择 ${ type== "请选择"?'selected="selected"':'' } >--请选择--</option>
            <option value=烤烟 ${ type== "烤烟"?'selected="selected"':'' } >烤烟</option>
            <option value=白肋烟 ${ type== "白肋烟"?'selected="selected"':'' }>白肋烟</option>
            <option value=马里兰烟 ${ type== "马里兰烟"?'selected="selected"':'' }>马里兰烟</option>
            <option value=香料烟 ${ type== "香料烟"?'selected="selected"':'' }>香料烟</option>
        </select></td>
        <td>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp品种:</td>
        <td><select name="pz" id="pz">
            <option value=请选择>--请选择--</option>
        </select></td>
        <td>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp等级:</
        <td><select name="lever" id="lever">
            <option value="">--请选择--</option>
        </select></td>
    <tr>
        <td><label> <input name="button1" type="submit"
            class="button" id="button1" value="数据查询" /> </label></td>
        <td><label> <input name="button1" type="submit"
            class="button" id="button2" value="图表查询" /> </label></td>
</table>
<%
    if(style.equals("感官质量")){
        %>
<table border="0" cellpadding="0" cellspacing="1" class="table-02">
    <tr>
        <% if(city.equals("请选择")){ %>
        <th>地市</th>
        <% } %>
        <% if(year.equals("请选择")){ %>
        <th>年份</th>
        <% } %>
        <% if(town.equals("请选择")){ %>
        <th>产县</th>
        <% } %>
        <% if(type.equals("请选择")){%>
        <th>烟叶类型</th>
        <% } %>
        <% if(lever.equals("请选择")){ %>
        <th>等级</th>
        <% } %>
        <th>香气质</th>
        <th>香气量</th>
        <th>杂气</th>
        <th>刺激性</th>
        <th>余味</th>
        <th>燃烧性</th>
        <th>灰色</th>
        <th>综合得分</th>
        <th>浓度</th>
        <th>劲头</th>
        <th>可用性</th>
        <th>香型</th>
    </tr>
    <%
            for(int i= 0;i<list.size();i++){
                Map map = (Map)list.get(i);
                %>
    <tr>
        <% if(city.equals("请选择")){ %>
        <td><%= map.get("City") %></td>
        <% } %>
        <% if(year.equals("请选择")){ %>
        <td><%= map.get("Year") %></td>
        <% } %>
        <% if(town.equals("请选择")){ %>
        <td><%= map.get("O_Place") %></td>
        <% } %>
        <% if(type.equals("请选择")){ %>
        <td><%= map.get("T_Type") %></td>
        <% } %>
        <% if(type.equals("请选择")){ %>
        <td><%= map.get("Lever") %></td>
        <% } %>
        <td><%= map.get("A_Qulity") %></td>
        <td><%= map.get("A_Quantity") %></td>
        <td><%= map.get("Mixedgas") %></td>
        <td><%= map.get("Irrit") %></td>
        <td><%= map.get("Aftaste") %></td>
        <td><%= map.get("Fla") %></td>
        <td><%= map.get("Gray") %></td>
        <td><%= map.get("O_Score") %></td>
        <td><%= map.get("Concen") %></td>
        <td><%= map.get("Strength") %></td>
        <td><%= map.get("Avail") %></td>
        <td><%= map.get("Flavor") %></td>
    </tr>
    <%
            }
        %>
</table>

<%
        }
        %> <%
    if(style.equals("化学成分")){
        %>
<table border="0" cellpadding="0" cellspacing="1" class="table-02">
    <tr>
        <% if(city.equals("请选择")){ %>
        <th>地市</th>
        <% } %>
        <% if(year.equals("请选择")){ %>
        <th>年份</th>
        <% } %>
        <% if(town.equals("请选择")){ %>
        <th>产县</th>
        <% } %>
        <% if(type.equals("请选择")){%>
        <th>烟叶类型</th>
        <% } %>
        <% if(lever.equals("请选择")){ %>
        <th>等级</th>
        <% } %>
        <th>烟碱百分比</th>
        <th>总糖百分比</th>
        <th>还原糖百分比</th>
        <th>总氮百分比</th>
        <th>钾百分比</th>
        <th>氯百分比</th>
        <th>氮碱比</th>
        <th>糖碱比</th>
        <th>两糖差</th>
        <th>钾氯比</th>

    </tr>
    <%
            for(int i= 0;i<list.size();i++){
                Map map = (Map)list.get(i);
                %>
    <tr>
        <% if(city.equals("请选择")){ %>
        <td><%= map.get("City") %></td>
        <% } %>
        <% if(year.equals("请选择")){ %>
        <td><%= map.get("Year") %></td>
        <% } %>
        <% if(town.equals("请选择")){ %>
        <td><%= map.get("O_Place") %></td>
        <% } %>
        <% if(type.equals("请选择")){ %>
        <td><%= map.get("T_Type") %></td>
        <% } %>
        <% if(type.equals("请选择")){ %>
        <td><%= map.get("Lever") %></td>
        <% } %>
        <td><%= map.get("T_B_Per") %></td>
        <td><%= map.get("T_S_Per") %></td>
        <td><%= map.get("S_Per") %></td>
        <td><%= map.get("N_Per") %></td>
        <td><%= map.get("K_Per") %></td>
        <td><%= map.get("Cl_Per") %></td>
        <td><%= map.get("N_Base") %></td>
        <td><%= map.get("S_Base") %></td>
        <td><%= map.get("Dif_Sugar") %></td>
        <td><%= map.get("K_Cl") %></td>

    </tr>
    <%
            }
        %>
</table>

<%
            }
        %> <%
    if(style.equals("外观质量")){
        %>
<table border="0" cellpadding="0" cellspacing="1" class="table-02">
    <tr>
        <% if(city.equals("请选择")){ %>
        <th>地市</th>
        <% } %>
        <% if(year.equals("请选择")){ %>
        <th>年份</th>
        <% } %>
        <% if(town.equals("请选择")){ %>
        <th>产县</th>
        <% } %>
        <% if(type.equals("请选择")){%>
        <th>烟叶类型</th>
        <% } %>
        <% if(lever.equals("请选择")){ %>
        <th>等级</th>
        <% } %>
        <th>颜色</th>
        <th>颜色分数</th>
        <th>成熟度</th>
        <th>成熟度分数</th>
        <th>叶片结构</th>
        <th>叶片结构分数</th>
        <th>身份</th>
        <th>身份分数</th>
        <th>油分</th>
        <th>油分分数</th>
        <th>色度</th>
        <th>色度分数</th>
        <th>光泽</th>
        <th>光泽分数</th>
        <th>叶面</th>
        <th>叶面分数</th>
        <th>弹性</th>
        <th>宽度</th>
        <th>长度</th>
        <th>均匀度百分比</th>
        <th>总分</th>
        <th>备注</th>
    </tr>
    <%
            for(int i= 0;i<list.size();i++){
                Map map = (Map)list.get(i);
                %>
    <tr>
        <% if(city.equals("请选择")){ %>
        <td><%= map.get("City") %></td>
        <% } %>
        <% if(year.equals("请选择")){ %>
        <td><%= map.get("Year") %></td>
        <% } %>
        <% if(town.equals("请选择")){ %>
        <td><%= map.get("O_Place") %></td>
        <% } %>
        <% if(type.equals("请选择")){ %>
        <td><%= map.get("T_Type") %></td>
        <% } %>
        <% if(type.equals("请选择")){ %>
        <td><%= map.get("Lever") %></td>
        <% } %>
        <td><%= map.get("Color") %></td>
        <td><%= map.get("C_Score") %></td>
        <td><%= map.get("Mat") %></td>
        <td><%= map.get("M_Score") %></td>
        <td><%= map.get("Lf_Struct") %></td>
        <td><%= map.get("L_S_Score") %></td>
        <td><%= map.get("Id") %></td>
        <td><%= map.get("Id_Score") %></td>
        <td><%= map.get("Oil") %></td>
        <td><%= map.get("OilScore") %></td>
        <td><%= map.get("C_Inten") %></td>
        <td><%= map.get("C_I_Score") %></td>
        <td><%= map.get("Luster") %></td>
        <td><%= map.get("L_Score") %></td>
        <td><%= map.get("Leaf") %></td>
        <td><%= map.get("Lf_Score") %></td>
        <td><%= map.get("Flex") %></td>
        <td><%= map.get("Width(cm)") %></td>
        <td><%= map.get("Length(cm)") %></td>
        <td><%= map.get("Uni_Per") %></td>
        <td><%= map.get("O_Score") %></td>
        <td><%= map.get("Remarks") %></td>

    </tr>
    <%
            }
        %>
</table>

<%
            }
        %> <%
    if(style.equals("物理性状")){
        %>
<table border="0" cellpadding="0" cellspacing="1" class="table-02">
    <tr>
        <% if(city.equals("请选择")){ %>
        <th>地市</th>
        <% } %>
        <% if(year.equals("请选择")){ %>
        <th>年份</th>
        <% } %>
        <% if(town.equals("请选择")){ %>
        <th>产县</th>
        <% } %>
        <% if(type.equals("请选择")){%>
        <th>烟叶类型</th>
        <% } %>
        <% if(lever.equals("请选择")){ %>
        <th>等级</th>
        <% } %>
        <th>单叶重(g)</th>
        <th>含梗率百分比</th>
        <th>吸湿性百分比</th>
        <th>填充值(cm&sup3;/g)</th>
        <th>叶片厚度(mm)</th>


    </tr>
    <%
            for(int i= 0;i<list.size();i++){
                Map map = (Map)list.get(i);
                %>
    <tr>
        <% if(city.equals("请选择")){ %>
        <td><%= map.get("City") %></td>
        <% } %>
        <% if(year.equals("请选择")){ %>
        <td><%= map.get("Year") %></td>
        <% } %>
        <% if(town.equals("请选择")){ %>
        <td><%= map.get("O_Place") %></td>
        <% } %>
        <% if(type.equals("请选择")){ %>
        <td><%= map.get("T_Type") %></td>
        <% } %>
        <% if(type.equals("请选择")){ %>
        <td><%= map.get("Lever") %></td>
        <% } %>
        <td><%= map.get("Lf_Wight(g)") %></td>
        <td><%= map.get("S_R_Per") %></td>
        <td><%= map.get("Hy_Per") %></td>
        <td><%= map.get("Fil(cm&sup3;/g)") %></td>
        <td><%= map.get("Lf_Thick") %></td>


    </tr>
    <%
            }
        %>
</table>

<%
            }
        %>

</body>
</html>


sevlet代码:
import
import
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class CityServlet
 */
public class ChaxunServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;
    private static final String CONTENT_TYPE = "text/xml";
      
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ChaxunServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        response.setContentType(CONTENT_TYPE);
        response.setCharacterEncoding("utf-8");
        request.setCharacterEncoding("utf-8");
        String city=request.getParameter("city");
        StringBuffer town=new StringBuffer("<?xml version='1.0' encoding='UTF-8'?><towns>");
        List citylist=townInit(city);
        for(int i=0;i<citylist.size();i++){
            town.append("<town>"+citylist.get(i)+"</town>");
            }
        town.append("</towns>");
        String type=request.getParameter("type");
        StringBuffer lever=new StringBuffer("<?xml version='1.0' encoding='UTF-8'?><types>");
        List typelist=leverInit(type);
        for(int i=0;i<typelist.size();i++){
            lever.append("<lever>"+typelist.get(i)+"</lever>");
            }
        lever.append("</levers>");
        PrintWriter out=response.getWriter();
        out.print(town.toString());
        out.print(lever.toString());
        out.flush();
        out.close();
    }

public List<String> townInit(String city){
    List<String> townList=new ArrayList<String>();
    if(city.equals("恩施")){
    townList.add("恩施");
    townList.add("巴东");
    townList.add("鹤峰");
    townList.add("利川");
    townList.add("来凤");
    townList.add("建始");
    townList.add("咸丰");
    townList.add("宣恩");
    }
    if(city.equals("十堰")){
    townList.add("竹溪");
    townList.add("房县");
    townList.add("竹山");
    townList.add("勋西");
    }
    if(city.equals("襄樊")){
    townList.add("南漳");
    townList.add("保康");
    }
    if(city.equals("宜昌")){
    townList.add("秭归");
    townList.add("兴山");
    townList.add("五峰");
    townList.add("长阳");
    }
   
    return townList;
   
}

public List<String> leverInit(String type){
    List<String> leverList=new ArrayList<String>();
    if(type.equals("烤烟")){
        leverList.add("B2F");
        leverList.add("C3F");
        leverList.add("X2F");
    }
    if(type.equals("白肋烟")){
        leverList.add("B2F");
        leverList.add("C3F");
        leverList.add("X2F");
        leverList.add("上二");
        leverList.add("中二");
        leverList.add("中四");
    }
    if(type.equals("马里兰烟")){
        leverList.add("B2");
        leverList.add("C2");
        leverList.add("X1");
        leverList.add("上二");
        leverList.add("下一");
        leverList.add("中二");
    }
    if(type.equals("香料烟")){
        leverList.add("上一");
        leverList.add("上二");
        leverList.add("中一");
        leverList.add("中二");
        leverList.add("下一");
    }
   
    return leverList;
   
}

}
搜索更多相关主题的帖子: 数据库 java 
2011-05-09 14:34
快速回复:ajax二级联动+读取数据库的值在页面显示
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.038201 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved