多级下拉菜单的级连显示问题。
在这里,我为了实现公司-部门级连显示问题,我编写了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" "http://www.w3.org/tr/html4/loose.dtd">
<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"> 当前位置:系统管理>>领导设置>>添加领导权限 </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" value="保存"> <input type="button" class="button" value="关闭" onclick="window.close();" > </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="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>
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 {
}
}
新闻热点
疑难解答
图片精选