关于级联操作的JavaWeb,望高手指教,对新手有用!

这里用到了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>

第一次写这个东西,不知道怎么附加项目。。。?找找看  只能这样了下载整个级联项目

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值