隨筆 - 59  文章 - 70  trackbacks - 0
          <2008年4月>
          303112345
          6789101112
          13141516171819
          20212223242526
          27282930123
          45678910

          常用鏈接

          留言簿(5)

          隨筆分類

          隨筆檔案

          搜索

          •  

          積分與排名

          • 積分 - 173879
          • 排名 - 340

          最新評論

          閱讀排行榜

          評論排行榜

          public ActionForward getOrganinfo_ajax(ActionMapping mapping, ActionForm form,
          HttpServletRequest request, HttpServletResponse response) {
          String level2OrganId = request.getParameter( " level2OrganId " );
          System.out.print(level2OrganId);
          IDReportLogic dreportLogic = (IDReportLogic)SpringFactory.getBeanFactory().getBean( " dreportLogic " );

          response.setContentType( " text/xml;charset=UTF-8 " );
          response.setHeader( " Cache-control " , " no-cache " );

          try {

          String orgLevel = request.getParameter( " orgLevel " );
          String orgId = request.getParameter( " orgId " );



          /**/ /*
          以下為前臺當中接受到的xml結構。

          StringBuffer sb = new StringBuffer();
          sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
          String str="<select><kkk><value>11111</value><text>北京</text></kkk>";
          String str2="<kkk><value>3333</value><text>上海</text></kkk></select>";
          sb.append(str);
          sb.append(str2); */

          PrintWriter out = response.getWriter();
          out.write(str);
          out.flush();
          return null ;
          } catch (Exception e) {
          // TODO 自動生成 catch 塊
          request.setAttribute( " info " , " 獲取二級機構異常! " );
          e.printStackTrace();
          return mapping.getInputForward();
          }

          }





          二級機構:


          < select name = " secOrganIdSel " id = " secOrganIdSel "
          onchange = " selectChangeListener('2',this.options[this.selectedIndex].value); " >
          < option value = " -1 " > 請選擇機構.. </ option >
          </ select >

          三級機構:
          < select name = " thdOrganIdSel " id = " thdOrganIdSel "
          onchange = " selectChangeListener('3',this.options[this.selectedIndex].value); " >
          < option value = " -1 " > 請選擇機構.. </ option >

          </ select >

          四級機構:
          < select name = " forthOrganIdSel " >
          < option value = " -1 " > 請選擇機構.. </ option >
          </ select >

          < script language = " javascript " type = " text/javascript " >
          var xmlHttp;

          function createXMLHttpRequest() {
          if (window.ActiveXObject) {
          xmlHttp = new ActiveXObject( " Microsoft.XMLHTTP " );
          } else if (window.XMLHttpRequest) {
          xmlHttp = new XMLHttpRequest();
          }
          }

          // 查詢指定頁面
          function selectChangeListener(orgLevel,orgId) {

          createXMLHttpRequest();

          var url = " <%=request.getContextPath()%>/dreportAction.do?method=getOrganinfo_ajax&orgLevel= " + orgLevel + " &orgId= " + orgId;
          xmlHttp.open( " get " ,url, true );
          if (orgLevel == ' 2 ') {
          // 如果是選擇默認的第一個,則是清空后面3級機構和4級機構。
          var tempSel = document.getElementById( " secOrganIdSel " );
          if (tempSel.options[tempSel.selectedIndex].value == - 1 ) {
          var tempSel_1 = document.getElementById( " thdOrganIdSel " );
          tempSel_1.options.length = 1 ;
          var tempSel_2 = document.getElementById( " forthOrganIdSel " );
          tempSel_2.options.length = 1 ;
          return false ;
          }
          xmlHttp.onreadystatechange = callback2;
          } else if (orgLevel == ' 3 ') {
          // 如果三級機構默認的是第一個選項,則清空第4級機構

          var tempSel = document.getElementById( " thdOrganIdSel " );
          if (tempSel.options[tempSel.selectedIndex].value == - 1 ) {
          var tempSel_2 = document.getElementById( " forthOrganIdSel " );
          tempSel_2.options.length = 1 ;
          return false ;
          }
          xmlHttp.onreadystatechange = callback3;
          }

          xmlHttp.send( null );
          }

          // 返回信息處理,二級機構下拉列表返回結果
          function callback2() {
          if (xmlHttp.readyState == 4 ) {
          if (xmlHttp.status == 200 ) {
          var xmlDoc = xmlHttp.responseXML;
          changeSel(' 2 ',xmlDoc);
          } else {
          window.alert( " 您所請求的頁面有異常。 " );
          }
          }
          }


          // 返回信息處理,三級機構下拉列表返回結果
          function callback3() {
          if (xmlHttp.readyState == 4 ) {
          if (xmlHttp.status == 200 ) {
          var xmlDoc = xmlHttp.responseXML;
          changeSel(' 3 ',xmlDoc);
          } else {
          window.alert( " 您所請求的頁面有異常。 " );
          }
          }
          }

          // 更新機構下拉列表
          function changeSel(orgLevel,xmlDoc) {

          // var xsel = xmlDoc.getElementsByTagName('kkk');
          var xsel = xmlDoc.documentElement.childNodes;

          // alert(xsel.length);
          if (orgLevel == ' 2 ') {
          // 二級機構,3級機構和4級機構需要清空。
          var tempSel_1 = document.getElementById( " thdOrganIdSel " );
          tempSel_1.options.length = 0 ;
          tempSel_1.add( new Option('請選擇機構',' - 1 '))
          var tempSel_2 = document.getElementById( " forthOrganIdSel " );
          tempSel_2.options.length = 0 ;
          tempSel_2.add( new Option('請選擇機構',' - 1 '))

          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);
          tempSel_1.add(option);
          }

          } else if (orgLevel == ' 3 ') {
          // 三級機構,四級機構需要清空

          var tempSel_2 = document.getElementById( " forthOrganIdSel " );
          tempSel_2.options.length = 0 ;
          tempSel_2.add( new Option('請選擇機構',' - 1 '))

          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);
          tempSel_2.add(option);
          }

          }

          }
          </ script >
          posted on 2008-04-10 10:19 JasonChou 閱讀(811) 評論(0)  編輯  收藏 所屬分類: j2ee
          主站蜘蛛池模板: 蓬莱市| 会昌县| 尉氏县| 丰宁| 集安市| 秀山| 卓尼县| 金乡县| 甘孜| 启东市| 璧山县| 和林格尔县| 沙田区| 陆河县| 丘北县| 正宁县| 华亭县| 囊谦县| 社会| 巍山| 北海市| 霞浦县| 新干县| 赞皇县| 红桥区| 类乌齐县| 陇西县| 永春县| 无极县| 云浮市| 忻州市| 绥阳县| 四平市| 太白县| 旅游| 瓦房店市| 信阳市| 忻城县| 扶风县| 江孜县| 曲麻莱县|