<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>级 联 特 效</title>
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<script type='text/javascript'
src='/AjaxT7-SSHDwr/dwr/interface/deptService.js'></script>
<script type='text/javascript'
src='/AjaxT7-SSHDwr/dwr/interface/employeeService.js'></script>
<script type='text/javascript' src='/AjaxT7-SSHDwr/dwr/engine.js'></script>
<script type='text/javascript' src='/AjaxT7-SSHDwr/dwr/util.js'></script>
<script type='text/javascript'>
function getAllDepts() {
deptService.getAllDepts(showDepts);
}
function showDepts(depts) {
DWRUtil.removeAllOptions("deptId");
DWRUtil.addOptions("deptId", depts);
}
function selectDept() {
employeeService.getAllEmployeesByDeptId(DWRUtil.getValue("deptId"),
showEmps);
}
function showEmps(emps) {
DWRUtil.removeAllOptions("empId");
DWRUtil.addOptions("empId", emps);
}
</script>
</head>
<body οnlοad="getAllDepts()">
<form name="myForm">
部门:
<select name="deptId" id="deptId" οnchange="javascript:selectDept();"></select>
员工:
<select name="empId" id="empId">
<option>
请选择部门
</option>
</select>
</form>
</body>
</html>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE dwr PUBLIC "-//GetAhead Limited//DTD Direct Web Remoting 2.0//EN" "http://www.getahead.ltd.uk/dwr/dwr20.dtd">
<dwr>
<allow>
<create creator="spring" javascript="userService">
<param name="beanName" value="userServiceBean" />
<include method="login"></include>
<include method="checkUserName"></include>
</create>
<create creator="spring" javascript="moduleService">
<param name="beanName" value="moduleServiceBean" />
<include method="getAllModules"></include>
</create>
<create creator="spring" javascript="deptService">
<param name="beanName" value="deptServiceBean" />
<include method="getAllDepts"></include>
</create>
<create creator="spring" javascript="employeeService">
<param name="beanName" value="employeeServiceBean" />
<include method="getAllEmployeesByDeptId"></include>
</create>
<convert match="com.tudou.ssh.entity.Employee" converter="bean"></convert>
<convert match="com.tudou.ssh.entity.Dept" converter="bean"></convert>
<convert match="com.tudou.ssh.entity.User" converter="bean"></convert>
<convert match="com.tudou.ssh.entity.Module" converter="bean"></convert>
</allow>
</dwr>
package com.tudou.ssh.service;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.tudou.ssh.dao.DeptDao;
import com.tudou.ssh.entity.Dept;
import com.tudou.ssh.util.BaseDao;
public class DeptService extends BaseDao implements DeptDao {
@SuppressWarnings("unchecked")
public Map<Integer, String> getAllDepts() {
Map<Integer, String> depts=new HashMap<Integer, String>();
List<Dept> depts2= this.getObjects();
for(Dept d:depts2){
depts.put(d.getDeptId(), d.getDeptName());
}
return depts;
}
}