这里用到了JSTL、Hibernate、jsp、javascript、和MS-sql,当然都是一些比较浅显的应用,希望对新手有用,高手提点提点!
具体的实现在index.jsp中,下面代码?新手注意如果直接复制代码基本是上是没用的!
<%@ page language="java" import="java.util.*,dao.*,entity.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%
List<Teacher> teaList=ServiceDao.fandAllTeacher();
List<Studnet> stuList=ServiceDao.fandAllStudnt();
request.setAttribute("stulist",stuList);
request.setAttribute("tealist",teaList);
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>T-S级联</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<script type="text/javascript">
function upTs(){
var div=document.getElementById("Sdiv");
var tid=document.getElementById("T").value;
if(tid==1)//如果老师id等于1 下面jstl里面的if 条件就判断tid=1 并显示只属于他的学生
{
div.innerHTML="<select name='S'><c:forEach items='${requestScope.stulist}' var='student'><c:if test='${student.teacher.id eq 1}'><option value='${student.id}'>${student.name}</option></c:if></c:forEach></select>";
}
if(tid==2)//同上
{
div.innerHTML="<select name='S'><c:forEach items='${requestScope.stulist}' var='student'><c:if test='${student.teacher.id eq 2}'><option value='${student.id}'>${student.name}</option></c:if></c:forEach></select>";
}
}
</script>
</head>
<body>
<div id="Tdiv">
<select name="T" id="T" οnchange="upTs()">
<c:forEach items="${requestScope.tealist}" var="teacher">
<option value="${teacher.id }">${teacher.name }</option>
</c:forEach>
</select>
</div>
<div id="Sdiv">
<select name="S">
<c:forEach items="${requestScope.stulist}" var="student">
<option value="${student.id}">${student.name}</option>
</c:forEach>
</select>
</div>
</body>
</html>
第一次写这个东西,不知道怎么附加项目。。。?找找看 只能这样了下载整个级联项目