dwr

 

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/share.jsp"%>
<%
	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>My JSP 'show.jsp' starting page</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'
			src='${path}/dwr/interface/stuService.js'></script>
		<script type='text/javascript' src='${path }/dwr/engine.js'></script>
		<script type='text/javascript' src='${path }/dwr/util.js'></script>
		<script type="text/javascript">			
			var page=1;					
			var pageCount=0;
						
			var firstHref="";			
			var previousHref="";
			var nextHref="";
			var lastHref="";		
			
			var stuPage="";
			
			function isPage(){		
				firstHref="javascript:getAllByPage("+1+")";			
				previousHref="javascript:getAllByPage("+ (page-1) +")";
				nextHref="javascript:getAllByPage("+ (page+1) +")";
				lastHref="javascript:getAllByPage("+pageCount+")";					
				if(page==1){
					stuPage="首页  上一页  <a href='"+nextHref+"'>下一页</a>  <a href='"+lastHref+"'>尾页</a>";		
				}				
				else if(page==pageCount){					
					stuPage="<a href='"+firstHref+"'>首页</a>  <a href='"+previousHref+"'>上一页</a>  下一页  尾页";
				}
				else if(page==1&&page==pageCount){
					stuPage="首页  上一页   下一页  尾页";
				}else{
					stuPage="<a href='"+firstHref+"'>首页</a>    <a href='"+previousHref+"'>上一页</a>    <a href='"+nextHref+"'>下一页</a>    <a href='"+lastHref+"'>尾页</a>";
				}
				document.getElementById("page").innerHTML=stuPage;
			}						
			function getAll(){
				stuService.getAll(page,setAll);
			}
			function getAllByPage(pageNum){
				page=pageNum;
				stuService.getAll(pageNum,setAll);
			}
			function setAll(stuList){
				DWRUtil.removeAllRows("student");
				DWRUtil.addRows("student",stuList,items);
				stuService.getPageCount(page,getPage);			
			}
			function deleteStu(stuId){
				stuService.deleteStu(stuId);
				getAll();
			}
			function getPage(stuPage){				
				page=stuPage.currentPage;
				pageCount=stuPage.pageCount;	
				isPage();
			}
			var items=[
				function(item){return item.stuId},
				function(item){return item.stuName},				
				function(item){return item.stuAge},
				function(item){return item.stuClass},
				function(item){						
						var stuDelete = document.createElement("a");
						stuDelete.innerHTML = "删除";
						stuDelete.href="javascript:deleteStu("+item.stuId+")";						
						return stuDelete;
				},
				function(item){ 
					var stuUpdate = document.createElement("a");
					stuUpdate.innerHTML = "修改";
					stuUpdate.href="javascript:toUpdateStu("+item.stuId+")";													 
					return stuUpdate;
				}
			];			
			function toUpdateStu(stuId){
				stuService.getById(stuId,setStu);
			}
			function setStu(student){
				document.getElementById("stuId").value=student.stuId;
				document.getElementById("stuName").value=student.stuName;
				document.getElementById("stuAge").value=student.stuAge;
				document.getElementById("stuClass").value=student.stuClass;
				document.getElementById("stuUpdate").disabled=false;
				document.getElementById("stuAdd").disabled=true;
			}
			
			function stuUpdate(stuId,stuName,stuAge,stuClass){
				if(stuValidate(stuName,stuAge,stuClass)){
					return;
				}
				stuService.update(stuId,stuName,stuAge,stuClass);				
				reset();
				getAllByPage(page);				
			}
			function add(stuName,stuAge,stuClass){
				if(stuValidate(stuName,stuAge,stuClass)){
					return;
				}
				stuService.add(stuName,stuAge,stuClass);								
				reset();
				getAllByPage(page);	
			}
			function reset(){
				document.getElementById("stuId").value="";
				document.getElementById("stuName").value="";
				document.getElementById("stuAge").value="";
				document.getElementById("stuClass").value="";
				document.getElementById("stuUpdate").disabled=true;
				document.getElementById("stuAdd").disabled=false;
			}
			function stuValidate(stuName,stuAge,stuClass){
				var re=/^[1-9][0-4]?[0-9]?$/;
				if(stuName==""){
					alert("学员姓名不能为空!");
					return true;
				}				
				if(!re.test(stuAge)){
					alert("学员年龄格式不正确!");
					return true;
				}
				if(stuClass==""){
					alert("学员所属班级不能为空!");
					return true;
				}
				return false;
			}
			window.onload=getAll;
		</script>
	</head>

	<body>
		<table border="1" align="center">
			<thead>
				<tr>
					<th>
						学员编号
					</th>
					<th>
						学员姓名
					</th>
					<th>
						学员年龄
					</th>
					<th>
						学员班级
					</th>
					<th>
						&nbsp;
					</th>
					<th>
						&nbsp;
					</th>
				</tr>
			</thead>
			<tbody id="student" align="center"></tbody>
		</table>
		<br>
		<div align="center" id="page">
		</div>
		<br>
		<br>
		<div align="center">
			学生信息操作
		</div>
		<div align="center" id="student">		
			学生编号:
			<input type="text" id="stuId" readonly="readonly">
			<br>
			学生姓名:
			<input type="text" id="stuName">
			<br>
			学生年龄:
			<input type="text" id="stuAge">
			<br>
			所属班级:
			<input type="text" id="stuClass">
			<br>
			<br>
			<input type="submit" onclick="add(stuName.value,stuAge.value,stuClass.value)" id="stuAdd" value="添加">
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			<input type="submit" onclick="stuUpdate(stuId.value,stuName.value,stuAge.value,stuClass.value)" id="stuUpdate" disabled="disabled" value="修改">
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			<input type="button" onclick="reset()" id="stuReset" value="重置">
		</div>
	</body>
</html>

你可能感兴趣的:(JavaScript,jsp,cache,css,DWR)