得到部门的servlet
//联动菜单。js调用查询部门字段 by xg
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
response.setCharacterEncoding("utf-8");
List<DepartmentInfo> list=null;
String wordXML = "";
try {
Reader reader = Resources.getResourceAsReader("cn/zc13/framework/persistence/config/SqlMapConfig.xml");
SqlMapClient sqlMapClient = SqlMapClientBuilder.buildSqlMapClient(reader);
try {
list = sqlMapClient.queryForList("publictool.selectAllDepartmentInfo");
for(DepartmentInfo u : list){
wordXML = wordXML +"<option value='" + u.getDepartmentID()+"'>"+ u.getName()+"</option>/n";
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
response.getWriter().write(wordXML);
}
得到人员的servlet
//联动菜单。js调用查询人员字段 by xg
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
response.setCharacterEncoding("utf-8");
String wordXML = "<script type='text/javascript'>var subclass = new Array();";
int i=0;
List<PersonInfo> list=null;
//String dep = request.getParameter("dep");
try {
Reader reader = Resources.getResourceAsReader("cn/zc13/framework/persistence/config/SqlMapConfig.xml");
SqlMapClient sqlMapClient = SqlMapClientBuilder.buildSqlMapClient(reader);
//wordXML = wordStartXML;
try {
//int org=Integer.parseInt(dep);
list = sqlMapClient.queryForList("publictool.selectAllPersonInfo");
// System.out.println(list);
for(PersonInfo u : list){
wordXML = wordXML +"subclass["+i+"]=new Array('"+u.getPersonID()+"','"+u.getName()+"','"+u.getDepartmentID()+"');";
i++;
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
wordXML = wordXML + "</script>";
response.getWriter().write(wordXML);
System.out.println(wordXML+"11111111");
}
相关的javabean
public class DepartmentInfo {
private int departmentID;
private String name;
public int getDepartmentID() {
return departmentID;
}
public void setDepartmentID(int departmentID) {
this.departmentID = departmentID;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public class PersonInfo {
private int personID;
private String name;
private String DepartmentID;
private String position;
public int getPersonID() {
return personID;
}
public void setPersonID(int personID) {
this.personID = personID;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDepartmentID() {
return DepartmentID;
}
public void setDepartmentID(String departmentID) {
DepartmentID = departmentID;
}
public String getPosition() {
return position;
}
public void setPosition(String position) {
this.position = position;
}
SQLMAP文件
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE sqlMap
PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"
"http://ibatis.apache.org/dtd/sql-map-2.dtd">
<sqlMap namespace="publictool">
<typeAlias alias="DepartmentInfo" type="cn.zc13.zcoa.publictool.pojo.DepartmentInfo"/>
<typeAlias alias="PersonInfo" type="cn.zc13.zcoa.publictool.pojo.PersonInfo"/>
<resultMap id="DepartmentInfoResult" class="DepartmentInfo">
<result property="departmentID" column="org_id"/>
<result property="name" column="org_name"/>
</resultMap>
<resultMap id="PersonInfoResult" class="PersonInfo">
<result property="personID" column="id"/>
<result property="name" column="u_name"/>
<result property="DepartmentID" column="org_id"/>
</resultMap>
<!-- 全部部门 -->
<select id="selectAllDepartmentInfo" resultMap="DepartmentInfoResult">
select org_id,org_name from u_orgnization
</select>
<!-- 全部人员 -->
<select id="selectAllPersonInfo" resultMap="PersonInfoResult">
select user_id as id,user_real_name as u_name,org_id from u_user
</select>
<!-- 指定人员 -->
<select id="selectOnePersonInfo" parameterClass="Integer" resultMap="PersonInfoResult">
select
user_id as id,
user_real_name as u_name
from u_user
where org_id = #org_id#
</select>
</sqlMap>
JS代码
/* --------------------------------------buy XG------------------------------------- */
$(document).ready(function(){
var selectNode=$("#BMselect");
var selectNode1=$("#BMselect1");
var url="servlet/ShowDepartment";
var length;
$.get(url,null,function(data){
/* 发送请求,并创建回调函数*/
if(data!=""){
/*-----START----------------------赋值 开始------------------------------------ */
selectNode.empty();
selectNode1.empty();
selectNode.append($("<option>").html("请选择部门").attr("value", "0"));
selectNode1.append($("<option>").html("请选择部门").attr("value", "0"));
selectNode.append(data);
selectNode1.append(data);
/*-----END----------------------赋值 结束------------------------------------ */
}else{
selectNode.empty();
selectNode1.empty();
selectNode.append($("<option>").html("没有部门").attr("value", "0"));
selectNode1.append($("<option>").html("没有部门").attr("value", "0"));
alert("没有部门信息!");
}
});
people_array();
})
function people_array()
{
var selectNode=$("#selectDIV");
var url="servlet/ShowPerson";
$.get(url,null,function(data){
/* 发送请求,并创建回调函数*/
selectNode.empty();
selectNode.append(data);
});
}
function listClass(Itemid,id,index){
document.getElementById(id).length=index;
//初始化下拉列表 清空下拉数据
//document.getElementById(id).options[0]=new Option("全部人员","")
for (i=0; i<subclass.length; i++)
{
if (subclass[i][2] == Itemid)
{
//建立 option
document.getElementById(id).options[document.getElementById(id).length] = new Option (subclass[i][1], subclass[i][0]);
//document.getElementById(id).options[document.getElementById(id).length] = new Option (subclass[i][1], subclass[i][0]);
}
}
}
页面调用
<!-- ~~~~~~~~~~~~联动菜单~~~~~~~~~~~~~XG~~~~~~~~ -->
<script type="text/javascript" src="resources_oa/javascript/jquery.js"></script>
<div id="selectDIV" name="selectDIV"></div>
<script type="text/javascript" src="resources_oa/javascript/selectjsp_list.js"></script>
<!-- ~~~~~~~~~~~~联动菜单~~~~~~~~~~~~~XG~~~~~~~~ -->
<select name="BMselect1" id="BMselect1" οnchange="listClass(this.value,'RYselect1',1);">
</select>
<select name="RYselect1" id="RYselect1">
<option value="1" selected="selected">所有人员</option>
</select>