Asp.net| Menu | problem | dropdown | show
Cascading display problems for multilevel drop-down menus.
Here, I wrote the leader_add_competence_dialogquery.jsp, Web.xml,selectcropdepartservlet.java class to achieve the company-department-level display problem.
The note is in the leader_add_competence_dialogquery. Jspchange_select () JavaScript function/ Selectcropdepart is the servlet class defined in Web.xml. We need to change in the implementation of the use of the red word marked out.
Where the leader_add_competence_dialogquery.jsp code is as follows:
<%@ 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" "HTTP://WWW.W3.ORG/TR/HTML4/LOOSE.DTD" >
<title> Add leadership Rights </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" >
<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 isn't 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= "><font face=" "Song Body" >
<div align= "left" ><font face= "song Body" color= "#ffffff" > Current Position: System Management >> Leadership Settings >> Add leadership Permissions </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" > Company:</td>
<td>
<select Name= "Corp" id= "Corp" >
<option value= "All" selected> company </OPTION></SELECT></td>
</tr>
<tr bgcolor= "#FFFFFF" >
<TD align= "Right" > Department:</td>
<td><select name= "Depart" id= "Depart" >
<option value= "All" selected> Department </OPTION></SELECT></td>
</tr>
<tr bgcolor= "#FFFFFF" >
<TD colspan= "2" align= "center" ><input type= "button" class= "button" style= "width:80px" value= "Save" > < Input type= "button" class= "button" value= "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%>
The Web.xml code is as follows:
<?xml version= "1.0" encoding= "UTF-8"?>
<web-app version= "2.4"
Xmlns= "HTTP://JAVA.SUN.COM/XML/NS/J2EE"
Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"
Xsi:schemalocation= "Http://java.sun.com/xml/ns/j2ee
Http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd ">
<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>
The Selectcropdepartservlet.java servlet class code is as follows
/**
* Extract data from the Sys04_machine table for level two Drop-down menus (company, department) and associated servlet classes
* @author Deng Hao
*/
public class Selectcropdepartservlet extends HttpServlet {
Public Selectcropdepartservlet () {
Super ();
}
public void Destroy () {
Super.destroy (); }
/**
* The Doget method of the servlet. <br>
*
* This is called when a form has it 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> all departments </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 {
}
}