⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 studentman.jsp

📁 JavaWeb标签应用开发(随书光盘)为方便读者阅读本书和调试程序
💻 JSP
字号:
,<%@ page contentType="text/html;charset=GB2312" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<fmt:requestEncoding value="gb2312"/>
<!------设置数据源------>
<sql:setDataSource dataSource="jdbc/sqlserver" var="sqlDS"/>
<html>
<!------系统交互javascript----->
<script language="JavaScript">
<!--
function delete_confirm() {
//按删除链接时,弹出确认对话框
   if(confirm("确认要删除吗?")){
  		return true;
	}else return false;	
}
-->
</script>
<body bgcolor="#DCDADA">
<!---------导航菜单------------->
<table border="0" width="100%">
  <tr>
    <td width="100%">
      <p align="left">您当前所在位置:学生信息管理-->查询和维护学生信息</p>
    </td>
  </tr>
<jsp:include page="navigator.txt"/>
</table>
<!---------数据输入------------->
<table border="1" width="100%" cellspacing="0" cellpadding="0" bordercolor="#808080" bordercolorlight="#808080" bordercolordark="#808080">
  <tr>
    <td width="100%">
      <table border="0" width="100%">
        <tr>
          <td width="100%" colspan="5">输入查询条件:<br><hr></td>
        </tr>
        <form name="add_student_form" action="studentman.jsp" method="post">
        <tr>
          <td width="24%" align="right">学生所属班级:</td>
          <td width="19%">
          <!-----生成学生所属班级下拉框------>
          <c:set var="selectRSSQL" value="select class_id,class_name from class"/>
          <sql:query sql="${selectRSSQL}" 
  			var="classRS" dataSource="${sqlDS}"/>
  		  <select name="class_id">
  		  	<option value="">====所有班级====</option>
  		  	<c:forEach items="${classRS.rowsByIndex}" var="cucN">
  		  		<option value="${cucN[0]}"
  		  		<c:if test="${cucN[0]==param.class_id}">selected</c:if>>
  		  		${cucN[1]}</option>
  		  	</c:forEach>
  		  </select> 		  
          </td>
          <td width="11%" align="right">学生姓名:</td>
          <td width="21%">
          <input type="text" name="student_name" maxlength="20" value="${param.student_name}">
          </td>
          <td width="25%"><input type="submit" value="提交"></td>
        </tr>
        </form>
      </table>
    </td>
  </tr>
</table><br>
<!-------生成查询数据库的SQL语句-------->
<c:set var="selectRSSQL" 
		value="select student_id,student_name,class_id from student"/>
<c:set var="selectCountSQL" 
		value="select count(*) as studentCount from student"/>
<!--如果class_id和student_name两个请求参数中有一个不为空-->
<c:if test="${not ((empty param.class_id)&&(empty param.student_name))}">
	<c:set var="selectRSSQL" value="${selectRSSQL} where "/>
	<c:set var="selectCountSQL" value="${selectCountSQL} where "/>
	<!--如果class_id请求参数不为空-->
	<c:if test="${not empty param.class_id}">
		<c:set var="selectRSSQL" 
			value="${selectRSSQL} class_id=${param.class_id}"/>
		<c:set var="selectCountSQL" 
			value="${selectCountSQL} class_id=${param.class_id}"/>
	</c:if>
	<!--如果student_name请求参数不为空-->
	<c:if test="${not empty param.student_name}">
	    <!--如果class_id请求参数为空,故selectRSSQL以where结尾-->
		<c:if test="${fn:endsWith(selectRSSQL,\" where \")}">
			<c:set var="selectRSSQL" 
				value="${selectRSSQL} student_name like '%${param.student_name}%'"/>
			<c:set var="selectCountSQL" 
				value="${selectCountSQL} student_name like '%${param.student_name}%'"/>
		</c:if>
		<!--如果class_id请求参数不为空,故selectRSSQL不以where结尾-->
		<c:if test="${not fn:endsWith(selectRSSQL,\" where \")}">
			<c:set var="selectRSSQL" 
				value="${selectRSSQL} and student_name like '%${param.student_name}%'"/>
			<c:set var="selectCountSQL" 
				value="${selectCountSQL} and student_name like '%${param.student_name}%'"/>
		</c:if>
	</c:if>
</c:if>
<!--查询出总记录条数-->
<sql:query sql="${selectCountSQL}" 
  				var="studentCountRS" dataSource="${sqlDS}"/>
<!--得到当前页的页号-->
<c:if test="${not empty param.page}">
  	<c:set var="page" value="${param.page}"/>
</c:if>
<c:if test="${empty param.page}">
  	<c:set var="page" value="1"/>
</c:if>
<!--得到总记录条数-->
<c:set var="studentCount" value="${studentCountRS.rowsByIndex[0][0]}"/>
<!--设置每页显示记录条数-->
<c:set var="pageSize" value="10"/>
<!--计算总页数-->
<c:if test="${studentCount%pageSize==0}">
  	<c:set var="pageCount" value="${studentCount/pageSize}"/>
</c:if>
<c:if test="${studentCount%pageSize!=0}">
  	<c:set var="pageCount" value="${studentCount/pageSize+1-(studentCount%pageSize)/pageSize}"/>
</c:if>
<fmt:formatNumber value="${pageCount}" maxFractionDigits="0" var="pageCount"/>   
<!--得到当前页数据在SQL查询结果中的起始位置-->
<c:set var="startPosition" value="${(page-1)*pageSize}"/>
<!--查询出当前页的数据-->
<sql:query 
  	sql="${selectRSSQL}" 
  	var="studentRS" dataSource="${sqlDS}" startRow="${startPosition}" maxRows="${pageSize}"/>
<!---------数据输出------------->
<table border="1" width="100%" cellspacing="0" cellpadding="0" bordercolor="#808080" bordercolorlight="#808080" bordercolordark="#808080">
  
  <tr>
    <td colspan="5" align="center">
    	所有学生(共${studentCount}位)&nbsp;&nbsp;&nbsp;&nbsp;
    	<c:if test="${studentCount!=0}"> 
		当前第${page}页,共${pageCount}页&nbsp;&nbsp;
    	<c:if test="${page!=1}">
  			<a href="${pageContext.request.requestURL}?page=1&class_id=${param.class_id}&student_name=${param.student_name}">首页</a>&nbsp;
  			<a href="${pageContext.request.requestURL}?page=${page-1}&class_id=${param.class_id}&student_name=${param.student_name}">上一页</a>
  		</c:if>
  		<c:if test="${page!=pageCount}">
  			&nbsp;<a href="${pageContext.request.requestURL}?page=${page+1}&class_id=${param.class_id}&student_name=${param.student_name}">下一页</a>
  			&nbsp;<a href="${pageContext.request.requestURL}?page=${pageCount}&class_id=${param.class_id}&student_name=${param.student_name}">尾页</a>)
  		</c:if>
  		</c:if>
    </td>
  </tr>
  <tr>
    <td width="10%" align="center">学生序号</td>
    <td width="25%" align="center">学生姓名</td>
    <td width="25%" align="center">学生所属班级</td>
    <td width="20%" align="center">修改?</td>
    <td width="20%" align="center">删除?</td>
  </tr>
<c:if test="${studentRS.rowCount>=1}">
  <c:forEach items="${studentRS.rowsByIndex}" var="cucN">
  <tr>
    <td align="center">${cucN[0]}</td>
    <td align="center">${cucN[1]}</td>
    <td align="center">
    <c:set var="selectRSSQL" 
    	value="select class_name from class where class_id=?"/>
    <sql:query sql="${selectRSSQL}" 
  		var="classRS" dataSource="${sqlDS}">
  		<sql:param value="${cucN[2]}"/>
  	</sql:query>
  	${classRS.rowsByIndex[0][0]}
    </td>
    <td align="center">
    <a href='student_update1.jsp?student_id=${cucN[0]}&class_id=${cucN[2]}'>修改</a>
    </td>
    <td align="center">
    <a href="student_delete.jsp?student_id=${cucN[0]}" onclick="return delete_confirm()">×</a>
    </td>
  </tr>
  </c:forEach> 
</c:if>  
</table><br>
</body>
</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -