table

          多級下拉菜單的級連顯示問題

          多級下拉菜單的級連顯示問題。

          在這里,我為了實現公司-部門級連顯示問題,我編寫了leader_add_competence_dialogquery.jsp ,web.xml,SelectCropDepartServlet.java 類。

          其中注意的是leader_add_competence_dialogquery中的.jspChange_Select() javascript函數中的/selectCropDepart是在web.xml中定義的servlet類。我們在實現應用當中需要修改的用紅字標出。

          其中leader_add_competence_dialogquery.jsp代碼如下:

          <%@ page contentType="text/html; charset=gbk" language="java" import="java.sql.*" errorPage="" %>

          <%@ page import="pub.*" %>

          <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "

          <html>

          <head>

          <title>添加領導權限</title>

          <link href="../css/putong.css" type="text/css" rel="stylesheet">

          <base target="_self">

          <META HTTP-EQUIV="Pragma" CONTENT="no-cache">

          <META HTTP-EQUIV="Cache-Control" CONTENT="no-cache">

          <META HTTP-EQUIV="Expires" CONTENT="0">

          </head>

          <script language="javascript">

              var req;

              window.onload=function(){

              }

                 function Change_Select(){      

                 var zhi = document.getElementById('Corp').value;

                   var url = "../selectCropDepart?id=" + escape(zhi);

                  //alert(url);

                   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 callback() {

              if (req.readyState == 4) {

                  if (req.status == 200) {

                           parseMessage();

                 // update the HTML DOM based on whether or not message is valid

                  }else{

                      alert ("Not able to retrieve description" +req.status+req.statusText);

           

                  }      

           

              }

             }

            

             function parseMessage() {

              var xmlDoc = req.responseXML.documentElement;

              var xSel = xmlDoc.getElementsByTagName('select');

              var select_root = document.getElementById('Depart');

              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 AddLeaderCompetence(){

                     var key=document.all.HiddenKey.value;      document.from1.action="leader_ctl.jsp?Oper=addCompetence&Key="+key;

                     document.from1.submit();

              }

          </script>

          <body>

          <%

                 String strUserID=request.getParameter("Key");

                         session.setAttribute("EmployUserID",strUserID);

          %>

          <form name="from1" action="leader_ctl.jsp"  method="post">

          <table cellSpacing="0" cellPadding="0" width="100%" bgColor="#bfcae6" border="0" background="../images/subtitle.gif">

              <tr>

                 <td width="99%" height="26"><FONT face="宋體">

                    <DIV align="left"><FONT face="宋體" color="#ffffff">&nbsp;&nbsp;當前位置:系統管理&gt;&gt;領導設置&gt;&gt;添加領導權限       </FONT>

                     </DIV>

                     </FONT>

                 </td>

              </tr>

            </table>

             <input type="hidden" name="HiddenKey" value="<%=strUserID%>" >

            <table width="100%" border="0" cellpadding="2" cellspacing="1" bgcolor="#AABDE0">

            <tr bgcolor="#FFFFFF">

            <td align="right">公司:</td>

            <td>   

              <SELECT name="Corp" id="Corp"  onChange="Change_Select()" >

                <OPTION value="all" selected>所有公司</OPTION></SELECT></td>

            </tr>

            <tr bgcolor="#FFFFFF">

            <td align="right">部門:</td>

            <td><SELECT name="Depart" id="Depart">

                <OPTION value="all" selected>所有部門</OPTION></SELECT></td>

            </tr>

            <tr bgcolor="#FFFFFF">

            <td colspan="2" align="center"><input type="button" onClick="AddLeaderCompetence();" class="button" style="width:80px" value="保存">&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" class="button" value="關閉" onClick="window.close();" style="width:80px"> </td> 

            </tr>

            </table> 

          </form>

          </body>

          <%   

              Conn conn=new Conn();

              String m1Script="";

              //String m2Script="";

              m1Script=PubClass.BindAllCorpList("document.all.Corp");

              //m2Script=PubClass.BindAllDepartList("document.all.Depart",""+session.getAttribute("cropid"));

              //sPositionList=conn.bindDropListSel("document.all.PositionName","select * from sys08_Position","PositionName","PositionID");

          %>

          <%= m1Script%>

          </html>

           

          Web.xml代碼如下:

          <?xml version="1.0" encoding="UTF-8"?>

          <web-app version="2.4"

              xmlns="

              xmlns:xsi="

              xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee

             

             <servlet>

              <servlet-name>selectCropDepart</servlet-name>

              <servlet-class>pub.SelectCropDepartServlet</servlet-class>

            </servlet>

            <servlet-mapping>

                  <servlet-name>selectCropDepart</servlet-name>

                  <url-pattern>/selectCropDepart</url-pattern> 

            </servlet-mapping>

          </web-app>

           

          SelectCropDepartServlet.java  Servlet類代碼如下

          /**

           * 從sys04_Machine表中取數據進行二級下拉菜單(公司,部門)及關聯的servlet類

           * @author 鄧浩

            */

          public class SelectCropDepartServlet extends HttpServlet {

                 public SelectCropDepartServlet() {

                        super();

                 }

                 public void destroy() {

                        super.destroy(); }

                 /**

                  * The doGet method of the servlet. <br>

                  *

                  * This method is called when a form has its tag value method equals to get.

                  *

                  * @param request the request send by the client to the server

                  * @param response the response send by the server to the client

                  * @throws ServletException if an error occurred

                  * @throws IOException if an error occurred

                  */

                 public void doGet(HttpServletRequest request, HttpServletResponse response)

                               throws ServletException, IOException {

                        response.setContentType("text/xml");

                        response.setCharacterEncoding("UTF-8");

                        response.setHeader("Cache-Control", "no-cache");      

                        String targetId = request.getParameter("id").toString();

                        String xml_start ="<selects>";

                       String xml_end = "</selects>";

                       String xml = "";

                       try{

                              Conn  conn=new Conn();

                              DataTable  dt=new DataTable();

                              String Sql="select * from sys04_Machine where cropid="+targetId;

                              ////System.out.println("Sql:"+Sql);

                               xml+= "<select><value>all</value><text>所有部門</text></select>" ;

                              int i=0;

                              if  (conn.querySql(Sql,dt)){

                                     while  (i<dt.getRowCount()){

                                            xml+= "<select><value>"+dt.getItemForName(i,"MachID").toString()+"</value><text>"+dt.getItemForName(i,"MachName").toString()+"</text></select>";  

                                            i=i+1;

                                     }

                              }

                           String last_xml = xml_start + xml + xml_end;

                           //System.out.println("last_xml:"+last_xml);

                          //  last_xml = new String(last_xml.getBytes("UTF-8"), "GB2312");

                          response.getWriter().write(last_xml);

                       }// try

                       catch  (Exception e){

                              System.out.print(e.getMessage());

                       }      

                 }

                 public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException{

                        doGet(request,response);

                }

                 public void init() throws ServletException {

                 }

          }

          posted on 2008-10-14 09:41 小卓 閱讀(275) 評論(0)  編輯  收藏 所屬分類: html and js

          主站蜘蛛池模板: 油尖旺区| 涪陵区| 隆昌县| 崇州市| 华容县| 永嘉县| 治县。| 乡宁县| 万源市| 香港| 景洪市| 桦甸市| 祁东县| 清镇市| 江川县| 宝兴县| 尼木县| 九寨沟县| 壤塘县| 南雄市| 沁源县| 连山| 宁南县| 宿迁市| 芷江| 浦北县| 拜泉县| 垫江县| 宁城县| 盐边县| 民和| 祁东县| 聂拉木县| 肇源县| 板桥市| 正镶白旗| 龙州县| 双峰县| 屯门区| 同德县| 南投县|