s2sh整合案例-学生信息管理系统(三)
今晚结束这个专题!完成了前面的server层,现在我们展示一下用户登录、班级信息管理与学生信息管理的整个业务流程。
用户登录:首先是登录页面,输入用户名与密码,验证码之后点击登录,发送一个url到controller,controller执行用户登录验证逻辑(期间获取调用service处理相关业务后返回的结果),验证结果绑定到会话域或者请求域中,转发或者重定向到新的页面。
首先是后台的LoginAction(其实就是一个Controller):
package com.steadyjack.web.action;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.interceptor.ServletRequestAware;
import org.springframework.context.annotation.Scope;
import com.opensymphony.xwork2.ActionSupport;
import com.steadyjack.server.model.User;
import com.steadyjack.server.service.UserService;
@Scope("prototype")
@Namespace("/")
@Action(value="login",results={@Result(name="success",type="redirect",location="/main.jsp"),
@Result(name="error",location="/index.jsp"),
@Result(name="exception",type="redirect",location="/exception.jsp")})
public class LoginAction extends ActionSupport implements ServletRequestAware{
/**
*
*/
private static final long serialVersionUID = 1L;
@Resource
private UserService userService;
private User user;
private String error;
private String imageCode;
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public String getError() {
return error;
}
public void setError(String error) {
this.error = error;
}
public String getImageCode() {
return imageCode;
}
public void setImageCode(String imageCode) {
this.imageCode = imageCode;
}
HttpServletRequest request;
@Override
public String execute() throws Exception {
// 获取Session
HttpSession session=request.getSession();
if(!imageCode.equals(session.getAttribute("sRand"))){
error="验证码错误!";
return ERROR;
}
try {
User currentUser=userService.login(user);
if(currentUser==null){
error="用户名或密码错误!";
return ERROR;
}else{
session.setAttribute("currentUser", currentUser);
return SUCCESS;
}
} catch (Exception e) {
//e.printStackTrace();
System.out.println(e.getMessage());
return "exception";
}
}
@Override
public void setServletRequest(HttpServletRequest request) {
// TODO Auto-generated method stub
this.request=request;
}
}
然后是页面index.jsp:
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>学生信息管理系统登录</title>
<script type="text/javascript" src="js/jquery-1.7.1.min.js"></script>
<!-- <script type="text/javascript" src="/style/admin/js/index.js"></script> -->
<script type="text/javascript">
function loginValidate(){
var userName=$('#userName').val();
var password=$('#password').val();
if (userName==null || password==null || trim(userName)=="" || trim(password)=="") {
$('#errorInfo').html("用户名或密码不能为空!");
return false;
}
var imageCode=$('#imageCode').val();
if (imageCode==null || imageCode=="") {
$('#errorInfo').html("验证码不能为空!");
return false;
}
$('#errorInfo').html("");
$('#userLoginForm').submit();
//alert("yes");
}
function resetValue() {
/*document.getElementById("userName").value = "";
document.getElementById("password").value = "";*/
$('#userName').val("");
$('#password').val("");
}
//去掉最后的空格
function trim(str){
return str.replace(/(^\s+)|(\s+$)/g, "");
}
function loadimage() {
//document.getElementById("randImage").src = "image.jsp?" + Math.random();
$('#randImage').src="image.jsp?"+Math.random();
}
</script>
</head>
<body>
<div align="center" style="padding-top: 50px;">
<form id="userLoginForm" action="login" method="post">
<table width="740" height="500" background="images/login2.jpg" >
<tr height="180">
<td colspan="4"></td>
</tr>
<tr height="10">
<td width="55%"></td>
<td width="7%">用户名:</td>
<td><input type="text" value="${user.userName }" name="user.userName" id="userName" onkeydown="if(event.keyCode==13){loginValidate();}"/></td>
<td width="35%"></td>
</tr>
<tr height="10">
<td width="55%"></td>
<td width="7%">密 码:</td>
<td><input type="password" value="${user.password }" name="user.password" id="password" onkeydown="if(event.keyCode==13){loginValidate();}"/></td>
<td width="35%"></td>
</tr>
<tr height="10">
<td width="55%"></td>
<td width="7%">验证码:</td>
<td><input type="text" value="${imageCode }" name="imageCode" id="imageCode" size="10" onkeydown="if(event.keyCode==13){loginValidate();}"/>
<img onclick="javascript:loadimage();" title="换一张试试" name="randImage" id="randImage" src="image.jsp" width="60" height="20" border="1" align="absmiddle"></td>
<td width="35%"></td>
</tr>
<tr height="12">
<td width="40%"></td>
<td width="10%"><input type="button" value="登录" style="width:50px;height: 22px;"
onclick="javascript:loginValidate();"/></td>
<td><input type="button" value="重置" onclick="resetValue()"/></td>
<td width="30%"></td>
</tr>
<tr height="10">
<td width="40%"></td>
<td colspan="3">
<font id="errorInfo" color="red">${error }</font>
</td>
</tr>
<tr >
<td></td>
</tr>
</table>
</form>
</div>
</body>
</html>
验证码页面image.jsp:
<%@ page contentType="image/jpeg"
import="java.awt.*,java.awt.image.*,java.util.*,javax.imageio.*" pageEncoding="utf-8"%>
<%!
Color getRandColor(int fc,int bc)
{
Random random = new Random();
if(fc>255) fc=255;
if(bc>255) bc=255;
int r=fc+random.nextInt(bc-fc);
int g=fc+random.nextInt(bc-fc);
int b=fc+random.nextInt(bc-fc);
return new Color(r,g,b);
}
%>
<%
out.clear();//这句针对resin服务器,如果是tomacat可以不要这句
response.setHeader("Pragma","No-cache");
response.setHeader("Cache-Control","no-cache");
response.setDateHeader("Expires", 0);
int width=60, height=20;
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics g = image.getGraphics();
Random random = new Random();
g.setColor(getRandColor(200,250));
g.fillRect(0, 0, width, height);
g.setFont(new Font("Times New Roman",Font.PLAIN,18));
g.setColor(getRandColor(160,200));
for (int i=0;i<155;i++)
{
int x = random.nextInt(width);
int y = random.nextInt(height);
int xl = random.nextInt(12);
int yl = random.nextInt(12);
g.drawLine(x,y,x+xl,y+yl);
}
String sRand="";
for (int i=0;i<4;i++){
String rand=String.valueOf(random.nextInt(10));
sRand+=rand;
g.setColor(new Color(20+random.nextInt(110),20+random.nextInt(110),20+random.nextInt(110)));
g.drawString(rand,13*i+6,16);
}
// 将认证码存入SESSION
session.setAttribute("sRand",sRand);
g.dispose();
ImageIO.write(image, "JPEG", response.getOutputStream());
%>
下面是登录页面图与登陆成功跳到的主界面图:
当然了,前端框架用的是jquery-easyui啦!!!
接下来,是班级管理与学生管理的Action(分别为GradeAction,StudentAction)
package com.steadyjack.web.action;
import java.util.List;
import javax.annotation.Resource;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.springframework.context.annotation.Scope;
import com.opensymphony.xwork2.ActionSupport;
import com.steadyjack.server.model.Grade;
import com.steadyjack.server.model.PageBean;
import com.steadyjack.server.service.GradeService;
import com.steadyjack.server.service.StudentService;
import com.steadyjack.server.util.ResponseUtil;
import com.steadyjack.server.util.StringUtil;
@Scope("prototype")
@Namespace("/")
@Action(value="grade")
public class GradeAction extends ActionSupport{
/**
*
*/
private static final long serialVersionUID = 1L;
@Resource
private GradeService gradeService;
@Resource
private StudentService studentService;
private String page;
private String rows;
private String s_gradeName="";
private Grade grade;
private String delIds;
private String id;
public String getPage() {
return page;
}
public void setPage(String page) {
this.page = page;
}
public String getRows() {
return rows;
}
public void setRows(String rows) {
this.rows = rows;
}
public Grade getGrade() {
return grade;
}
public void setGrade(Grade grade) {
this.grade = grade;
}
public String getS_gradeName() {
return s_gradeName;
}
public void setS_gradeName(String s_gradeName) {
this.s_gradeName = s_gradeName;
}
public String getDelIds() {
return delIds;
}
public void setDelIds(String delIds) {
this.delIds = delIds;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
@Override
public String execute() throws Exception {
PageBean pageBean=new PageBean(Integer.parseInt(page),Integer.parseInt(rows));
try{
if(grade==null){
grade=new Grade();
}
grade.setGradeName(s_gradeName);
JSONObject result=new JSONObject();
List<Grade> gradeList=gradeService.gradeList(pageBean, grade);
JSONArray jsonArray=new JSONArray();
for(int i=0;i<gradeList.size();i++){
Grade grade=(Grade)gradeList.get(i);
JSONObject jsonObject=new JSONObject();
jsonObject.put("id", grade.getId());
jsonObject.put("gradeName", grade.getGradeName());
jsonObject.put("gradeDesc", grade.getGradeDesc());
jsonArray.add(jsonObject);
}
long total=gradeService.gradeCount(grade);
result.put("rows", jsonArray);
result.put("total", total);
ResponseUtil.write(ServletActionContext.getResponse(), result);
}catch(Exception e){
e.printStackTrace();
}
return null;
}
public String delete()throws Exception{
try{
JSONObject result=new JSONObject();
String str[]=delIds.split(",");
for(int i=0;i<str.length;i++){
boolean f=studentService.getStudentByGradeId(str[i]);
if(f){
result.put("errorIndex", i);
result.put("errorMsg", "班级下面有学生,不能删除!");
ResponseUtil.write(ServletActionContext.getResponse(), result);
return null;
}
}
int delNums=gradeService.gradeDelete(delIds);
if(delNums>0){
result.put("success", "true");
result.put("delNums", delNums);
}else{
result.put("errorMsg", "删除失败");
}
ResponseUtil.write(ServletActionContext.getResponse(), result);
}catch(Exception e){
e.printStackTrace();
}
return null;
}
public String save()throws Exception{
if(StringUtil.isNotEmpty(id)){
grade.setId(Integer.parseInt(id));
}
try{
int saveNums=0;
JSONObject result=new JSONObject();
saveNums=gradeService.gradeSave(grade);
if(saveNums>0){
result.put("success", "true");
}else{
result.put("success", "true");
result.put("errorMsg", "保存失败");
}
ResponseUtil.write(ServletActionContext.getResponse(), result);
}catch(Exception e){
e.printStackTrace();
}
return null;
}
@SuppressWarnings("static-access")
public String gradeComboList()throws Exception{
try{
JSONArray jsonArray=new JSONArray();
JSONObject jsonObject=new JSONObject();
jsonObject.put("id", "");
jsonObject.put("gradeName", "请选择...");
jsonArray.add(jsonObject);
jsonArray.addAll(jsonArray.fromObject(gradeService.gradeList(null,null)));
//jsonArray=jsonArray.fromObject(gradeService.gradeList(null,null));
ResponseUtil.write(ServletActionContext.getResponse(), jsonArray);
}catch(Exception e){
e.printStackTrace();
}
return null;
}
}
package com.steadyjack.web.action;
import java.util.List;
import javax.annotation.Resource;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.springframework.context.annotation.Scope;
import com.opensymphony.xwork2.ActionSupport;
import com.steadyjack.server.model.PageBean;
import com.steadyjack.server.model.Student;
import com.steadyjack.server.service.GradeService;
import com.steadyjack.server.service.StudentService;
import com.steadyjack.server.util.DateUtil;
import com.steadyjack.server.util.ResponseUtil;
import com.steadyjack.server.util.StringUtil;
@Scope("prototype")
@Namespace("/")
@Action(value="student")
public class StudentAction extends ActionSupport{
/**
*
*/
private static final long serialVersionUID = 1L;
@Resource
private StudentService studentService;
@Resource
private GradeService gradeService;
private Student student;
private String s_stuNo;
private String s_stuName;
private String s_sex;
private String s_bbirthday;
private String s_ebirthday;
private String s_gradeId;
private String page;
private String rows;
private String delIds;
private String stuId;
public Student getStudent() {
return student;
}
public void setStudent(Student student) {
this.student = student;
}
public String getS_stuNo() {
return s_stuNo;
}
public void setS_stuNo(String s_stuNo) {
this.s_stuNo = s_stuNo;
}
public String getS_stuName() {
return s_stuName;
}
public void setS_stuName(String s_stuName) {
this.s_stuName = s_stuName;
}
public String getS_sex() {
return s_sex;
}
public void setS_sex(String s_sex) {
this.s_sex = s_sex;
}
public String getS_bbirthday() {
return s_bbirthday;
}
public void setS_bbirthday(String s_bbirthday) {
this.s_bbirthday = s_bbirthday;
}
public String getS_ebirthday() {
return s_ebirthday;
}
public void setS_ebirthday(String s_ebirthday) {
this.s_ebirthday = s_ebirthday;
}
public String getS_gradeId() {
return s_gradeId;
}
public void setS_gradeId(String s_gradeId) {
this.s_gradeId = s_gradeId;
}
public String getPage() {
return page;
}
public void setPage(String page) {
this.page = page;
}
public String getRows() {
return rows;
}
public void setRows(String rows) {
this.rows = rows;
}
public String getDelIds() {
return delIds;
}
public void setDelIds(String delIds) {
this.delIds = delIds;
}
public String getStuId() {
return stuId;
}
public void setStuId(String stuId) {
this.stuId = stuId;
}
@Override
public String execute() throws Exception {
PageBean pageBean=new PageBean(Integer.parseInt(page),Integer.parseInt(rows));
student=new Student();
if(s_stuNo!=null){
student.setStuNo(s_stuNo);
student.setStuName(s_stuName);
student.setSex(s_sex);
if(StringUtil.isNotEmpty(s_gradeId)){
student.setGradeId(Integer.parseInt(s_gradeId));
}
}
try{
JSONObject result=new JSONObject();
List<Student> studentList=studentService.studentList(pageBean,student,s_bbirthday,s_ebirthday);
JSONArray jsonArray=new JSONArray();
for(int i=0;i<studentList.size();i++){
Student student=(Student)studentList.get(i);
JSONObject jsonObject=new JSONObject();
jsonObject.put("stuId", student.getStuId());
jsonObject.put("stuNo", student.getStuNo());
jsonObject.put("stuName", student.getStuName());
jsonObject.put("sex", student.getSex());
jsonObject.put("birthday", DateUtil.formatDate(student.getBirthday(), "yyyy-MM-dd"));
jsonObject.put("gradeId", student.getGradeId());
jsonObject.put("email", student.getEmail());
jsonObject.put("stuDesc", student.getStuDesc());
jsonObject.put("gradeName", gradeService.getGradeById(student.getGradeId()).getGradeName());
jsonArray.add(jsonObject);
}
long total=studentService.studentCount(student,s_bbirthday,s_ebirthday);
result.put("rows", jsonArray);
result.put("total", total);
ResponseUtil.write(ServletActionContext.getResponse(), result);
}catch(Exception e){
e.printStackTrace();
}
return null;
}
public String delete()throws Exception{
try{
JSONObject result=new JSONObject();
int delNums=studentService.studentDelete(delIds);
if(delNums>0){
result.put("success", "true");
result.put("delNums", delNums);
}else{
result.put("errorMsg", "删除失败");
}
ResponseUtil.write(ServletActionContext.getResponse(), result);
}catch(Exception e){
e.printStackTrace();
}
return null;
}
public String save()throws Exception{
if(StringUtil.isNotEmpty(stuId)){
student.setStuId(Integer.parseInt(stuId));
}
try{
int saveNums=0;
JSONObject result=new JSONObject();
saveNums=studentService.studentSave(student);
if(saveNums>0){
result.put("success", "true");
}else{
result.put("success", "true");
result.put("errorMsg", "保存失败");
}
ResponseUtil.write(ServletActionContext.getResponse(), result);
}catch(Exception e){
e.printStackTrace();
}
return null;
}
}
main.jsp:
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8" isELIgnored="false"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>学生信息管理系统主界面</title>
<%
// 权限验证
if(session.getAttribute("currentUser")==null){
response.sendRedirect("index.jsp");
return;
}
%>
<link rel="stylesheet" type="text/css" href="jquery-easyui-1.3.3/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="jquery-easyui-1.3.3/themes/icon.css">
<script type="text/javascript" src="jquery-easyui-1.3.3/jquery.min.js"></script>
<script type="text/javascript" src="jquery-easyui-1.3.3/jquery.easyui.min.js"></script>
<script type="text/javascript" src="jquery-easyui-1.3.3/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript">
function checkLogout(){
if (confirm("是否退出当前系统?")) {
window.location.href="logout";
}
}
$(function(){
// 数据
var treeData=[{
text:"系统信息管理",
children:[{
text:"班级信息管理",
attributes:{
url:"gradeInfoManage.jsp"
}
},{
text:"学生信息管理",
attributes:{
url:"studentInfoManage.jsp"
}
},{
text:"班主任信息管理",
attributes:{
url:"index.jsp"
}
}]
},{
text:"基础信息管理",
children:[{
text:"用户管理",
attributes:{
url:"gradeInfoManage.jsp"
}
},{
text:"数据字典",
attributes:{
url:"studentInfoManage.jsp"
}
}]
}];
// 实例化树菜单
$("#tree").tree({
data:treeData,
lines:true,
onClick:function(node){
if(node.attributes){
openTab(node.text,node.attributes.url);
}
}
});
// 新增Tab
function openTab(text,url){
if($("#tabs").tabs('exists',text)){
$("#tabs").tabs('select',text);
}else{
var content="<iframe frameborder='0' scrolling='auto' style='width:100%;height:100%' src="+url+"></iframe>";
$("#tabs").tabs('add',{
title:text,
closable:true,
content:content
});
}
}
});
</script>
<!-- base需要放到head中 -->
<base href="<%=basePath%>">
</head>
<body class="easyui-layout">
<div region="north" style="height: 80px;background-color: #E0EDFF">
<a href="main.jsp"><div align="left" style="width: 60%;float: left"><img src="images/main.jpg"></div></a>
<div style="padding-top: 35px;float: right;padding-right: 25px;">
当前用户: <font color="red">${currentUser.userName }</font>
用户身份类型: <font color="red" size="3">
<c:choose>
<c:when test="${currentUser.type==1 }">系统管理员</c:when>
<c:when test="${currentUser.type==2 }">班主任</c:when>
<c:otherwise>学生</c:otherwise>
</c:choose>
</font>
<a style="text-decoration: none;cursor: pointer;" title="退出系统" onclick="checkLogout()"><font size="3" color="blue">退出</font></a>
</div>
</div>
<div region="center">
<div class="easyui-tabs" fit="true" border="false" id="tabs">
<div title="首页" >
<div align="center" style="padding-top: 100px;"><font color="red" size="13">欢迎使用学生信息管理系统</font></div>
</div>
</div>
</div>
<div region="west" style="width: 230px;" title="导航菜单" split="true">
<ul id="tree"></ul>
</div>
<div region="south" style="height: 25px;" align="center">版权所有 <a href="http://blog.csdn.net/u013871100"><font size="2">csdn博主 steadyjack</font></a></div>
</body>
</html>
gradeInfoManage.jsp页面:
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>班级信息管理</title>
<link rel="stylesheet" type="text/css" href="jquery-easyui-1.3.3/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="jquery-easyui-1.3.3/themes/icon.css">
<script type="text/javascript" src="jquery-easyui-1.3.3/jquery.min.js"></script>
<script type="text/javascript" src="jquery-easyui-1.3.3/jquery.easyui.min.js"></script>
<script type="text/javascript" src="jquery-easyui-1.3.3/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript">
var url;
function searchGrade(){
$('#dg').datagrid('load',{
//s_gradeName传到后台
s_gradeName:$('#s_gradeName').val()
});
}
//批量删除
function deleteGrade(){
var selectedRows=$("#dg").datagrid('getSelections');
if(selectedRows.length==0){
$.messager.alert("系统提示","请选择要删除的数据!");
return;
}
var strIds=[];
for(var i=0;i<selectedRows.length;i++){
strIds.push(selectedRows[i].id);
}
var ids=strIds.join(",");
$.messager.confirm("系统提示","您确认要删掉这<font color=red>"+selectedRows.length+"</font>条数据吗?",function(r){
if(r){
$.post("grade!delete",{delIds:ids},function(result){
if(result.success){
$.messager.alert("系统提示","您已成功删除<font color=red>"+result.delNums+"</font>条数据!");
$("#dg").datagrid("reload");
}else{
$.messager.alert('系统提示','<font color=red>'+selectedRows[result.errorIndex].gradeName+'</font>'+result.errorMsg);
}
},"json");
}
});
}
//打开“添加信息”窗口
function openGradeAddDialog(){
$("#dlg").dialog("open").dialog("setTitle","添加班级信息");
url="grade!save";
}
//打开修改信息的窗口
function openGradeModifyDialog(){
var selectedRows=$("#dg").datagrid('getSelections');
if(selectedRows.length!=1){
$.messager.alert("系统提示","请选择一条要编辑的数据!");
return;
}
var row=selectedRows[0];
$("#dlg").dialog("open").dialog("setTitle","编辑班级信息");
// $("#fm").form("load",row);
$("#gradeName").val(row.gradeName);
$("#gradeDesc").val(row.gradeDesc);
url="grade!save?id="+row.id;
}
//关闭对话框
function closeGradeDialog(){
$("#dlg").dialog("close");
resetValue();
}
//重置值
function resetValue(){
$("#gradeName").val("");
$("#gradeDesc").val("");
}
//保存
function saveGrade(){
$("#fm").form("submit",{
url:url,
onSubmit:function(){
return $(this).form("validate");
},
success:function(result){
if(result.errorMsg){
$.messager.alert("系统提示",result.errorMsg);
return;
}else{
$.messager.alert("系统提示","保存成功");
resetValue();
$("#dlg").dialog("close");
$("#dg").datagrid("reload");
}
}
});
}
</script>
</head>
<body style="margin: 5px;">
<table id="dg" title="班级信息" class="easyui-datagrid" fitColumns="true"
pagination="true" rownumbers="true" url="grade" fit="true" toolbar="#tb">
<thead>
<tr>
<th field="cb" checkbox="true"></th>
<th field="id" width="50">编号</th>
<th field="gradeName" width="100">班级名称</th>
<th field="gradeDesc" width="250">班级描述</th>
</tr>
</thead>
</table>
<div id="tb">
<div>
<a href="javascript:openGradeAddDialog()" class="easyui-linkbutton" iconCls="icon-add" plain="true">添加</a>
<a href="javascript:openGradeModifyDialog()" class="easyui-linkbutton" iconCls="icon-edit" plain="true">修改</a>
<a href="javascript:deleteGrade()" class="easyui-linkbutton" iconCls="icon-remove" plain="true">删除</a>
</div>
<div> 班级名称: <input type="text" name="s_gradeName" id="s_gradeName"/><a href="javascript:searchGrade()" class="easyui-linkbutton" iconCls="icon-search" plain="true">搜索</a></div>
</div>
<div id="dlg" class="easyui-dialog" style="width: 400px;height: 280px;padding: 10px 20px"
closed="true" buttons="#dlg-buttons">
<form id="fm" method="post">
<table>
<tr>
<td>班级名称:</td>
<td><input type="text" name="grade.gradeName" id="gradeName" class="easyui-validatebox" required="true"/></td>
</tr>
<tr>
<td valign="top">班级描述:</td>
<td><textarea rows="7" cols="30" name="grade.gradeDesc" id="gradeDesc"></textarea></td>
</tr>
</table>
</form>
</div>
<div id="dlg-buttons">
<a href="javascript:saveGrade()" class="easyui-linkbutton" iconCls="icon-ok">保存</a>
<a href="javascript:closeGradeDialog()" class="easyui-linkbutton" iconCls="icon-cancel">关闭</a>
</div>
</body>
</html>
studentInfoManage.jsp页面:
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>学生信息管理</title>
<link rel="stylesheet" type="text/css" href="jquery-easyui-1.3.3/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="jquery-easyui-1.3.3/themes/icon.css">
<script type="text/javascript" src="jquery-easyui-1.3.3/jquery.min.js"></script>
<script type="text/javascript" src="jquery-easyui-1.3.3/jquery.easyui.min.js"></script>
<script type="text/javascript" src="jquery-easyui-1.3.3/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript">
var url;
function deleteStudent(){
var selectedRows=$("#dg").datagrid('getSelections');
if(selectedRows.length==0){
$.messager.alert("系统提示","请选择要删除的数据!");
return;
}
var strIds=[];
for(var i=0;i<selectedRows.length;i++){
strIds.push(selectedRows[i].stuId);
}
var ids=strIds.join(",");
$.messager.confirm("系统提示","您确认要删掉这<font color=red>"+selectedRows.length+"</font>条数据吗?",function(r){
if(r){
$.post("student!delete",{delIds:ids},function(result){
if(result.success){
$.messager.alert("系统提示","您已成功删除<font color=red>"+result.delNums+"</font>条数据!");
$("#dg").datagrid("reload");
}else{
$.messager.alert('系统提示',result.errorMsg);
}
},"json");
}
});
}
function searchStudent(){
$('#dg').datagrid('load',{
s_stuNo:$('#s_stuNo').val(),
s_stuName:$('#s_stuName').val(),
s_sex:$('#s_sex').combobox("getValue"),
s_bbirthday:$('#s_bbirthday').datebox("getValue"),
s_ebirthday:$('#s_ebirthday').datebox("getValue"),
s_gradeId:$('#s_gradeId').combobox("getValue")
});
}
function openStudentAddDialog(){
$("#dlg").dialog("open").dialog("setTitle","添加学生信息");
url="student!save";
}
function saveStudent(){
$("#fm").form("submit",{
url:url,
onSubmit:function(){
if($('#sex').combobox("getValue")==""){
$.messager.alert("系统提示","请选择性别");
return false;
}
if($('#gradeId').combobox("getValue")==""){
$.messager.alert("系统提示","请选择所属班级");
return false;
}
return $(this).form("validate");
},
success:function(result){
if(result.errorMsg){
$.messager.alert("系统提示",result.errorMsg);
return;
}else{
$.messager.alert("系统提示","保存成功");
resetValue();
$("#dlg").dialog("close");
$("#dg").datagrid("reload");
}
}
});
}
function resetValue(){
$("#stuNo").val("");
$("#stuName").val("");
$("#sex").combobox("setValue","");
$("#birthday").datebox("setValue","");
$("#gradeId").combobox("setValue","");
$("#email").val("");
$("#stuDesc").val("");
}
function closeStudentDialog(){
$("#dlg").dialog("close");
resetValue();
}
function openStudentModifyDialog(){
var selectedRows=$("#dg").datagrid('getSelections');
if(selectedRows.length!=1){
$.messager.alert("系统提示","请选择一条要编辑的数据!");
return;
}
var row=selectedRows[0];
$("#dlg").dialog("open").dialog("setTitle","编辑学生信息");
//$("#fm").form("load",row);
$("#stuNo").val(row.stuNo);
$("#stuName").val(row.stuName);
$("#sex").combobox("setValue",row.sex);
$("#birthday").datebox("setValue",row.birthday);
$("#gradeId").combobox("setValue",row.gradeId);
$("#email").val(row.email);
$("#stuDesc").val(row.stuDesc);
url="student!save?stuId="+row.stuId;
}
</script>
</head>
<body style="margin: 5px;">
<table id="dg" title="学生信息" class="easyui-datagrid" fitColumns="true"
pagination="true" rownumbers="true" url="student" fit="true" toolbar="#tb">
<thead>
<tr>
<th field="cb" checkbox="true"></th>
<th field="stuId" width="50" align="center">编号</th>
<th field="stuNo" width="100" align="center">学号</th>
<th field="stuName" width="100" align="center">姓名</th>
<th field="sex" width="100" align="center">性别</th>
<th field="birthday" width="100" align="center">出生日期</th>
<th field="gradeId" width="100" align="center" hidden="true">班级ID</th>
<th field="gradeName" width="100" align="center">班级名称</th>
<th field="email" width="150" align="center">Email</th>
<th field="stuDesc" width="250" align="center">学生备注</th>
</tr>
</thead>
</table>
<div id="tb">
<div>
<a href="javascript:openStudentAddDialog()" class="easyui-linkbutton" iconCls="icon-add" plain="true">添加</a>
<a href="javascript:openStudentModifyDialog()" class="easyui-linkbutton" iconCls="icon-edit" plain="true">修改</a>
<a href="javascript:deleteStudent()" class="easyui-linkbutton" iconCls="icon-remove" plain="true">删除</a>
</div>
<div> 学号: <input type="text" name="s_stuNo" id="s_stuNo" size="10"/>
姓名: <input type="text" name="s_stuName" id="s_stuName" size="10"/>
性别: <select class="easyui-combobox" id="s_sex" name="s_sex" editable="false" panelHeight="auto">
<option value="">请选择...</option>
<option value="男">男</option>
<option value="女">女</option>
</select>
出生日期: <input class="easyui-datebox" name="s_bbirthday" id="s_bbirthday" editable="false" size="10"/>-><input class="easyui-datebox" name="s_ebirthday" id="s_ebirthday" editable="false" size="10"/>
所属班级: <input class="easyui-combobox" id="s_gradeId" name="s_gradeId" size="10" data-options="panelHeight:'auto',editable:false,valueField:'id',textField:'gradeName',url:'grade!gradeComboList'"/>
<a href="javascript:searchStudent()" class="easyui-linkbutton" iconCls="icon-search" plain="true">搜索</a></div>
</div>
<div id="dlg" class="easyui-dialog" style="width: 570px;height: 350px;padding: 10px 20px"
closed="true" buttons="#dlg-buttons">
<form id="fm" method="post">
<table cellspacing="5px;">
<tr>
<td>学号:</td>
<td><input type="text" name="student.stuNo" id="stuNo" class="easyui-validatebox" required="true"/></td>
<td> </td>
<td>姓名:</td>
<td><input type="text" name="student.stuName" id="stuName" class="easyui-validatebox" required="true"/></td>
</tr>
<tr>
<td>性别:</td>
<td><select class="easyui-combobox" id="sex" name="student.sex" editable="false" panelHeight="auto" style="width: 155px">
<option value="">请选择...</option>
<option value="男">男</option>
<option value="女">女</option>
</select></td>
<td></td>
<td>出生日期:</td>
<td><input class="easyui-datebox" name="student.birthday" id="birthday" required="true" editable="false" /></td>
</tr>
<tr>
<td>班级名称:</td>
<td><input class="easyui-combobox" id="gradeId" name="student.gradeId" data-options="panelHeight:'auto',editable:false,valueField:'id',textField:'gradeName',url:'grade!gradeComboList'"/></td>
<td></td>
<td>Email:</td>
<td><input type="text" name="student.email" id="email" class="easyui-validatebox" required="true" validType="email"/></td>
</tr>
<tr>
<td valign="top">学生备注:</td>
<td colspan="4"><textarea rows="7" cols="50" name="student.stuDesc" id="stuDesc"></textarea></td>
</tr>
</table>
</form>
</div>
<div id="dlg-buttons">
<a href="javascript:saveStudent()" class="easyui-linkbutton" iconCls="icon-ok">保存</a>
<a href="javascript:closeStudentDialog()" class="easyui-linkbutton" iconCls="icon-cancel">关闭</a>
</div>
</body>
</html>
下面是运行效果图:
好了,就介绍到这里吧!!!个人QQ:1948831260 为方便有兴趣的人研究,特意上传了源代码!!!系统源代码