JAVA涂鴉
          關(guān)于JAVA的點(diǎn)點(diǎn)滴滴
          posts - 50,  comments - 689,  trackbacks - 0
          基于網(wǎng)友的要求,我貼出在項(xiàng)目中用到的三級(jí)聯(lián)動(dòng)的代碼:

          jsp的代碼:

          <%@?page?contentType?=?"text/html;?charset=GBK"??import="java.util.*,com.wehave.hyerp.procurement.domain.Cgsqd"%>
          <%@?taglib?uri="struts-html"?prefix="html"?%>
          <%@?taglib?uri="struts-logic"?prefix="logic"?%>
          <%@?taglib?uri="struts-bean"?prefix="bean"?%>
          <html>
          ????
          <head>
          ????????
          <title>?</title>
          ????????
          <link?rel?=?"stylesheet"?type?=?"text/css"?href?=?"../css/olstyle.css">????
          ????????
          <SCRIPT?type="text/javascript">
          ????????var?req;
          ????????window.onload
          =function(){
          ????????}

          ????????
          ????????function?Change_Select()
          ????????
          {
          ????????????var?zhi
          =document.getElementById('m_gykfwzlbb_lbbm').value;
          ????????????var?url
          ="sqdSelect.go?method=getSkill&id="+zhi;
          ????????????
          if(zhi=="0"){
          ????????????????alert(
          "請(qǐng)選擇您要察看的信息");
          ???????????????????
          return;
          ????????????}
          else{
          ????????????????
          if(window.XMLHttpRequest)
          ????????????????
          {
          ????????????????????req
          =new?XMLHttpRequest();
          ????????????????}
          else?if(window.ActiveXObject)
          ????????????????
          {
          ????????????????????req
          =new?ActiveXObject("Microsoft.XMLHTTP");
          ????????????????}

          ????????????????
          ????????????????
          if(req)
          ????????????????
          {
          ????????????????????req.open(
          "GET",url,true);
          ????????????????????req.onreadystatechange
          =callback;
          ????????????????????req.send(
          null);
          ????????????????}

          ????????????}

          ????????}

          ????????
          ????????function?Change_Select2()
          ????????
          {
          ????????????var?zhi
          =document.getElementById('m_lbbm_se').value;
          ????????????
          //alert(zhi.substring(0,2));
          ????????????if(zhi=="0"){
          ????????????????alert(
          "請(qǐng)選擇您要察看的信息");
          ???????????????????
          return;
          ???????????????}

          ????????????
          if(zhi.substring(0,2)=="WY"){
          ????????????????var?url
          ="sqdSelect.go?method=getSkill2&id="+zhi;
          ????????????????
          if(window.XMLHttpRequest)
          ????????????????
          {
          ????????????????????req
          =new?XMLHttpRequest();
          ????????????????}
          else?if(window.ActiveXObject)
          ????????????????
          {
          ????????????????????req
          =new?ActiveXObject("Microsoft.XMLHTTP");
          ????????????????}

          ????????????????
          ????????????????
          if(req)
          ????????????????
          {
          ????????????????????req.open(
          "GET",url,true);
          ????????????????????req.onreadystatechange
          =callback2;
          ????????????????????req.send(
          null);
          ????????????????}

          ????????????}
          else{
          ????????????????parent.topFram.location?
          ="sqdSelectAll.go?method=getlistAll&id="+zhi;
          ????????????}

          ????????}

          ????????
          ????????function?Change_Select3()
          ????????
          {
          ????????????var?zhi
          =document.getElementById('m_lbbm_th').value;
          ????????????
          //alert(zhi.substring(0,2));
          ????????????if(zhi=="0"){
          ????????????????alert(
          "請(qǐng)選擇您要察看的信息");
          ???????????????????
          return;
          ???????????????}
          else{
          ????????????????parent.topFram.location?
          ="sqdSelectAll.go?method=getlistAll2&id="+zhi;
          ????????????}

          ????????}

          ????????
          ????????function?callback()
          ????????
          {
          ????????????
          if(req.readyState?==?4)
          ????????????
          {
          ????????????????
          if(req.status?==?200)
          ????????????????
          {
          ????????????????????parseMessage();
          ????????????????}
          else{
          ????????????????????alert(
          "Not?able?to?retrieve?description"+req.statusText);
          ????????????????}

          ????????????}

          ????????}

          ????????
          ????????function?callback2()
          ????????
          {
          ????????????
          if(req.readyState?==?4)
          ????????????
          {
          ????????????????
          if(req.status?==?200)
          ????????????????
          {
          ????????????????????parseMessage2();
          ????????????????}
          else{
          ????????????????????alert(
          "Not?able?to?retrieve?description"+req.statusText);
          ????????????????}

          ????????????}

          ????????}

          ????????
          ????????function?parseMessage()
          ????????
          {
          ????????????var?xmlDoc
          =req.responseXML.documentElement;
          ????????????var?xSel
          =xmlDoc.getElementsByTagName('select');
          ????????????var?select_root
          =document.getElementById('m_lbbm_se');
          ????????????select_root.options.length
          =0;
          ????????????
          ????????????
          for(var?i=0;i<xSel.length;i++)
          ????????????
          {
          ????????????????var?xValue
          =xSel[i].childNodes[0].firstChild.nodeValue;
          ????????????????var?xText
          =xSel[i].childNodes[1].firstChild.nodeValue;
          ????????????????var?option
          =new?Option(xText,xValue);
          ????????????????
          try{
          ????????????????????select_root.add(option);
          ????????????????}
          catch(e){
          ????????????????}

          ????????????}

          ????????}

          ????????
          ????????function?parseMessage2()
          ????????
          {
          ????????????var?xmlDoc
          =req.responseXML.documentElement;
          ????????????var?xSel
          =xmlDoc.getElementsByTagName('select');
          ????????????var?select_root
          =document.getElementById('m_lbbm_th');
          ????????????select_root.options.length
          =0;
          ????????????
          ????????????
          for(var?i=0;i<xSel.length;i++)
          ????????????
          {
          ????????????????var?xValue
          =xSel[i].childNodes[0].firstChild.nodeValue;
          ????????????????var?xText
          =xSel[i].childNodes[1].firstChild.nodeValue;
          ????????????????var?option
          =new?Option(xText,xValue);
          ????????????????
          try{
          ????????????????????select_root.add(option);
          ????????????????}
          catch(e){
          ????????????????}

          ????????????}

          ????????}

          ????????
          ????????
          ????????
          ????
          </SCRIPT>
          ????
          </head>

          <body?bgcolor?=?"#C8D0D4">
          ????
          <html:form?action="/cgsqdNewAction.go">?
          ????
          <TABLE?class?=?"cbToolbar"?id?=?"idToolbar"?cellpadding?=?'0'?cellspacing?=?'0'>
          ????????
          <TR?align?=?"left"?valign?=?"top"?>
          ????????????
          <TD??NOWRAP>&nbsp;物質(zhì)類(lèi)別:&nbsp;&nbsp;
          ????????????????
          <html:select?property="m_gykfwzlbb_lbbm"?onchange="Change_Select()">
          ????????????????????
          <html:option?value="0">請(qǐng)選擇</html:option>
          ???????????????????????
          <html:options?collection="LbfList"?property="m_gykfwzlbb_lbbm"?labelProperty="m_gykfwzlbb_lbmc"/>
          ????????????????
          </html:select>?&nbsp;
          ????????????????
          <html:select?property="m_lbbm_se"?styleId="m_lbbm_se"?onchange="Change_Select2()">
          ????????????????????
          <html:option?value="0">&nbsp;&nbsp;&nbsp;</html:option>
          ????????????????
          </html:select>
          ????????????????
          <html:select?property="m_lbbm_th"?styleId="m_lbbm_th"?onchange="Change_Select3()">
          ????????????????????
          <html:option?value="0">&nbsp;&nbsp;&nbsp;</html:option>
          ????????????????
          </html:select>
          ????????????????
          ????????????
          </TD>
          ????????????
          ????????
          </tr>
          ????
          </table>
          ?????
          </html:form>
          </body>
          </html>

          action中的代碼:
          /**
          ?????*?
          ?????*?查詢(xún)物質(zhì)編碼類(lèi)別列表操作(一級(jí))
          ?????*?
          */

          ????
          public?ActionForward?doSelectWzlb(
          ????????????ActionMapping?mapping,
          ????????????ActionForm?form,
          ????????????HttpServletRequest?req,
          ????????????HttpServletResponse?res)?
          {
          ????????HttpSession?session?
          =?req.getSession();
          ????????UserSession?userSession?
          =
          ????????????(UserSession)?session.getAttribute(
          "userSession");
          ????????permission.setUserID(userSession.getUserId());
          ????????permission.setUserName(userSession.getUserName());
          ????????permission.setModuleName(
          "m_cgsqd");
          ????????permission.setActionStr(
          "'m_select'");
          ????????
          if(permissionService.checkUserPermission(permission)){
          ????????????
          int?updateSign=0;
          ????????????
          try{
          ????????????????cgsqdService.updateCgsqwzhzb_sqsl();
          ????????????????updateSign
          =1;
          ????????????}
          catch(Exception?e){
          ????????????????e.printStackTrace();
          ????????????????updateSign
          =0;
          ????????????}

          ????????????
          if(updateSign==1){
          ????????????????List?LbfList
          =cgsqdService.treeListWzlb2();
          ????????????????req.setAttribute(
          "LbfList",LbfList);
          ????????????????
          return?mapping.findForward("tools");
          ????????????}
          else{
          ????????????????
          return?null;
          ????????????}

          ????????}
          else{
          ????????????
          return?mapping.findForward("failure");
          ????????}

          ????}

          ????
          ????
          /**
          ?????*?
          ?????*?查詢(xún)物質(zhì)編碼類(lèi)別列表操作(二級(jí))
          ?????*?
          */

          ????
          public?ActionForward?doSelectWzlb1(
          ????????????ActionMapping?mapping,
          ????????????ActionForm?form,
          ????????????HttpServletRequest?req,
          ????????????HttpServletResponse?res)?
          {
          ????????HttpSession?session?
          =?req.getSession();
          ????????UserSession?userSession?
          =
          ????????????(UserSession)?session.getAttribute(
          "userSession");
          ????????permission.setUserID(userSession.getUserId());
          ????????permission.setUserName(userSession.getUserName());
          ????????permission.setModuleName(
          "m_cgsqd");
          ????????permission.setActionStr(
          "'m_select'");
          ????????
          if(permissionService.checkUserPermission(permission)){
          ????????????
          int?updateSign=0;
          ????????????
          try{
          ????????????????cgsqdService.updateCgsqwzhzb_sqsl();
          ????????????????updateSign
          =1;
          ????????????}
          catch(Exception?e){
          ????????????????e.printStackTrace();
          ????????????????updateSign
          =0;
          ????????????}

          ????????????
          if(updateSign==1){
          ????????????????List?LbfList
          =cgsqdService.treeListWzlb2();
          ????????????????req.setAttribute(
          "LbfList",LbfList);
          ????????????????
          return?mapping.findForward("tools1");
          ????????????}
          else{
          ????????????????
          return?null;
          ????????????}

          ????????}
          else{
          ????????????
          return?mapping.findForward("failure");
          ????????}

          ????}

          ????
          ????
          /**
          ?????*?
          ?????*?查詢(xún)物質(zhì)編碼類(lèi)別列表操作(三級(jí))
          ?????*?
          */

          ????
          public?ActionForward?getSkill(
          ????????????ActionMapping?mapping,
          ????????????ActionForm?form,
          ????????????HttpServletRequest?req,
          ????????????HttpServletResponse?res)?
          {
          ????????HttpSession?session?
          =?req.getSession();
          ????????UserSession?userSession?
          =
          ????????????(UserSession)?session.getAttribute(
          "userSession");
          ????????permission.setUserID(userSession.getUserId());
          ????????permission.setUserName(userSession.getUserName());
          ????????permission.setModuleName(
          "m_cgsqd");
          ????????permission.setActionStr(
          "'m_select'");
          ????????
          if(permissionService.checkUserPermission(permission)){
          ????????????String?id
          =req.getParameter("id");
          ????????????
          ????????????res.setContentType(
          "text/xml;charset=GBK");
          ????????????res.setHeader(
          "Cache-Control","no-cache");
          ????????????String?xml_start
          ="<?xml?version=\"1.0\"?encoding=\"GBK\"?>";
          ????????????xml_start
          +="<selects>";
          ????????????String?xml_end
          ="</selects>";
          ????????????String?xml
          ="<select><value>0</value><text>請(qǐng)選擇</text></select>";
          ????????????String?m_lbbm_se
          ="";
          ????????????String?m_lbmc_se
          ="";
          ????????????List?LbfList
          =null;
          ????????????
          if(id.equals("WY")){
          ????????????????LbfList
          =cgsqdService.treeListWzlb3_2(id);
          ????????????}
          else{
          ????????????????LbfList
          =cgsqdService.treeListWzlb3_1(id);????
          ????????????}

          ????????????Iterator?it
          =LbfList.iterator();
          ????????????
          while(it.hasNext()){
          ????????????????Cgsqd?cgsqd
          =(Cgsqd)it.next();
          ????????????????m_lbbm_se
          =cgsqd.getM_gykfwzlbb_lbbm();
          ????????????????m_lbmc_se
          =cgsqd.getM_gykfwzlbb_lbmc();
          ????????????????xml?
          +="<select><value>"+m_lbbm_se+"</value><text>"+m_lbmc_se+"</text></select>";
          ????????????}

          ????????????String?last_xml
          =xml_start+xml+xml_end;
          ????????????logger.debug(
          "XML是:"+last_xml);
          ????????????
          try?{
          ????????????????res.getWriter().write(last_xml);
          ????????????}
          ?catch?(IOException?e)?{
          ????????????????e.printStackTrace();
          ????????????}

          ????????????
          return?null;
          ????????}
          else{
          ????????????
          return?null;
          ????????}

          ????}

          主要代碼就這些,去掉一些權(quán)限大代碼,真正的代碼并不多。
          posted on 2006-08-09 15:21 千山鳥(niǎo)飛絕 閱讀(13624) 評(píng)論(10)  編輯  收藏 所屬分類(lèi): Ajax

          FeedBack:
          # re: Ajax實(shí)現(xiàn)三級(jí)聯(lián)動(dòng)下拉框
          2006-08-26 19:28 | yyw_1023
          高手就是高手!佩服佩服!!!!!!!!!!1  回復(fù)  更多評(píng)論
            
          # re: Ajax實(shí)現(xiàn)三級(jí)聯(lián)動(dòng)下拉框
          2006-09-15 11:18 | zch
          我按照你的方法做了下,在onchange的時(shí)候,報(bào)了一個(gè)這樣的錯(cuò)誤~!
          no action instance /SeclectAll.do ...
          配置
          <action path="/SelectAll"
          type="com.hdtq.main.SelectAction"
          scope="request">
          <forward name="success" path="/MyLogin.jsp"/>
          ................
          請(qǐng)問(wèn)這是怎么回事呢???
          ..
          var url="/teach/SelectAll.do?method=g1&id="+zhi;
          ....  回復(fù)  更多評(píng)論
            
          # re: Ajax實(shí)現(xiàn)三級(jí)聯(lián)動(dòng)下拉框
          2007-06-12 11:37 | 啊啊
          能不能用三維數(shù)組實(shí)現(xiàn)三級(jí)聯(lián)動(dòng)阿?  回復(fù)  更多評(píng)論
            
          # re: Ajax實(shí)現(xiàn)三級(jí)聯(lián)動(dòng)下拉框
          2007-06-12 14:20 | 千山鳥(niǎo)飛絕
          @啊啊
          可以參考這篇文章:
          javascript實(shí)現(xiàn)二級(jí)聯(lián)動(dòng)下拉框
          http://www.aygfsteel.com/rickhunter/articles/64607.html  回復(fù)  更多評(píng)論
            
          # re: Ajax實(shí)現(xiàn)三級(jí)聯(lián)動(dòng)下拉框[未登錄](méi)
          2007-09-14 17:05 | liu
          我這里報(bào)錯(cuò),是Not able to retrieve descriptionUnkown  回復(fù)  更多評(píng)論
            
          # re: Ajax實(shí)現(xiàn)三級(jí)聯(lián)動(dòng)下拉框[未登錄](méi)
          2008-05-09 10:07 | 七七
          支持一下,借用啦。  回復(fù)  更多評(píng)論
            
          # re: Ajax實(shí)現(xiàn)三級(jí)聯(lián)動(dòng)下拉框[未登錄](méi)
          2008-10-25 12:52 | 紅狼
          請(qǐng)問(wèn)你的UserSession是從哪得到的。能把詳細(xì)類(lèi)創(chuàng)建寫(xiě)一下嗎?Action怎么與頁(yè)面交互的?急求回答75974082@qq.com  回復(fù)  更多評(píng)論
            
          # re: Ajax實(shí)現(xiàn)三級(jí)聯(lián)動(dòng)下拉框
          2008-10-28 22:40 | wa
          javax.servlet.ServletException: javax.servlet.jsp.JspException: Cannot find bean under name LbfList
          為什么會(huì)這樣的啊?????????????  回復(fù)  更多評(píng)論
            
          # re: Ajax實(shí)現(xiàn)三級(jí)聯(lián)動(dòng)下拉框
          2008-12-28 20:25 | 盜版
          原創(chuàng)? 絕對(duì)的“原創(chuàng)”!!!!!!!!!!!  回復(fù)  更多評(píng)論
            
          # re: Ajax實(shí)現(xiàn)三級(jí)聯(lián)動(dòng)下拉框
          2011-10-13 09:17 | tao
          厲害!我是新手。還得向您請(qǐng)教個(gè)問(wèn)題。幫忙到我的看看我這段代碼。。。
          http://blog.csdn.net/myjsj_2006/article/details/6868701
          加載特別慢,能不能快點(diǎn)
            回復(fù)  更多評(píng)論
            
          正在閱讀:



          <2007年6月>
          272829303112
          3456789
          10111213141516
          17181920212223
          24252627282930
          1234567

          常用鏈接

          留言簿(35)

          隨筆檔案

          文章分類(lèi)

          文章檔案

          好友的blog

          我的其他blog

          老婆的Blog

          搜索

          •  

          積分與排名

          • 積分 - 775408
          • 排名 - 56

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          主站蜘蛛池模板: 宁夏| 长宁县| 建湖县| 琼结县| 三门峡市| 新野县| 红桥区| 棋牌| 芒康县| 高淳县| 和龙市| 大埔区| 东乌珠穆沁旗| 扬中市| 襄城县| 疏勒县| 孝义市| 涟水县| 忻城县| 子洲县| 台州市| 青田县| 荆门市| 江华| 习水县| 江津市| 肇州县| 彭泽县| 沈丘县| 湖南省| 定州市| 景宁| 浠水县| 平阳县| 林周县| 雅安市| 故城县| 鲁山县| 宣威市| 木兰县| 武宁县|