学生信息管理系统(2更改自己的信息 退出当前账号(更改密码))
·
学生信息管理系统
工具eclipse
主要操作登陆,增删查改
2更改自己的信息 退出当前账号(更改密码)
Servlet
SystemServlet(加上学生列表)
private void studentList(HttpServletRequest request,HttpServletResponse response) throws IOException{
try {
//RequestDispatcher对象从客户端获取请求request,并把它们传递给服务器上的servlet,html或jsp。
request.getRequestDispatcher("view/studentList.jsp").forward(request, response);
}catch (ServletException e) {
e.printStackTrace();
}
}
StudentServlet(对学生进行操作)
public class StudentServlet extends HttpServlet {
public void doGet(HttpServletRequest request,HttpServletResponse response) throws IOException{
doPost(request, response);
}
public void doPost(HttpServletRequest request,HttpServletResponse response) throws IOException{
String method = request.getParameter("method");
if("toStudentListView".equals(method)){
//studentList(request,response);
}else if("EditStudent".equals(method)){
//editStudent(request,response);
}
}
//获取学生列表
private void editStudentList(HttpServletRequest request,HttpServletResponse response) {
String name=request.getParameter("studentName");
Integer currentPage = request.getParameter("page") == null ? 1 : Integer.parseInt(request.getParameter("page"));
Integer pageSize = request.getParameter("rows") == null ? 999 : Integer.parseInt(request.getParameter("rows"));
Integer clazz = request.getParameter("clazzid") == null ? 0 : Integer.parseInt(request.getParameter("clazzid"));
//获取当前登录的用户类型 以此来有不同的功能
int userType =Integer.parseInt(request.getSession().getAttribute("userType").toString());
Student student=new Student();
student.setName(name);
student.setClassId(clazz);
if(userType==2) {
//currentUser当前用户
//是学生,只能查看自己的信息
//loginServlet 已经把type写入usertype user是student
Student currentUser=(Student)request.getSession().getAttribute("user");
student.setId(currentUser.getId());
}
//查看数据 当前班级的人
StudentDao studentDao=new StudentDao();
List<Student> clazzList = studentDao.getStudentList(student, new Page(currentPage, pageSize));
int total=studentDao.getStudentListTotal(student);
studentDao.closeCon();//关闭数据库连接
response.setCharacterEncoding("UTF-8");
//显示学生列表以及行
Map<String, Object> ret = new HashMap<String, Object>();
ret.put("total", total);
ret.put("rows", clazzList);
try {
String from = request.getParameter("from");
if("combox".equals(from)){
response.getWriter().write(JSONArray.fromObject(clazzList).toString());
}else{
response.getWriter().write(JSONObject.fromObject(ret).toString());
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
//编辑学生
private void editStudent(HttpServletRequest request,
HttpServletResponse response) {
String name=request.getParameter("name");
int id = Integer.parseInt(request.getParameter("id"));
String sex = request.getParameter("sex");
String mobile = request.getParameter("mobile");
String qq = request.getParameter("qq");
int clazzId = Integer.parseInt(request.getParameter("clazzid"));
Student student=new Student();
student.setClassId(clazzId);
student.setMobile(mobile);
student.setName(name);
student.setId(id);
student.setQq(qq);
student.setSex(sex);
//把上面的数据写入数据库
StudentDao studentDao=new StudentDao();
if(studentDao.editStudent(student)) {
try {
response.getWriter().write("success");//给前端数据传入更改成功了
} catch(IOException e) {
e.printStackTrace();
}finally {
studentDao.closeCon();//关闭数据库连接
}
}
}
//跳转到学生列表
private void studentList(HttpServletRequest request,
HttpServletResponse response) throws IOException {
// TODO Auto-generated method stub
try {
request.getRequestDispatcher("view/studentList.jsp").forward(request, response);
} catch (ServletException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
//在这之前还得去StudentDao加上一个更改学生的方法 (之前写的时候忘记写了)
编写studentList.jsp(这里真的很烦我把值名和学生类里面的写的不一致导致取值错误 )
$(function(){
//datagrid初始化
$('#dataList').datagrid({
title:'学生列表',
iconCls:'icon-more',//图标
border: true,
collapsible:false,//是否可折叠的
fit: true,//自动大小
method: "post",
url:"StudentServlet?method=StudentList&t="+new Date().getTime(),
idField:'id',
singleSelect:false,//是否单选
pagination:true,//分页控件
rownumbers:true,//行号
sortName:'id',
sortOrder:'DESC',
remoteSort: false,
columns: [[
{field:'chk',checkbox: true,width:50},
//这里的sId对应的是之前loginservlet里面login写入session了只需要写出entity里面的变量名
{field:'id',title:'ID',width:50, sortable: true},
{field:'sId',title:'学号',width:200, sortable: true},
{field:'name',title:'姓名',width:200},
{field:'sex',title:'性别',width:100},
{field:'mobile',title:'电话',width:150},
{field:'qq',title:'QQ',width:150},
{field:'classId',title:'班级',width:150,
formatter: function(value,row,index){
if (row.classId){
var clazzList = $("#clazzList").combobox("getData");
for(var i=0;i<clazzList.length;i++ ){
//console.log(clazzList[i]);
if(row.classId == clazzList[i].id)return clazzList[i].name;
}
return row.classId;
} else {
return 'not found';
}
}
},
]],
toolbar: "#toolbar",
onBeforeLoad : function(){
try{
$("#clazzList").combobox("getData")
}catch(err){
preLoadClazz();
}
}
});
//设置分页控件
var p = $('#dataList').datagrid('getPager');
$(p).pagination({
pageSize: 10,//每页显示的记录条数,默认为10
pageList: [10,20,30,50,100],//可以设置每页记录条数的列表
beforePageText: '第',//页数文本框前显示的汉字
afterPageText: '页 共 {pages} 页',
displayMsg: '当前显示 {from} - {to} 条记录 共 {total} 条记录',
});
//设置工具类按钮
$("#add").click(function(){
$("#addDialog").dialog("open");
});
//修改
$("#edit").click(function(){
var selectRows = $("#dataList").datagrid("getSelections");
if(selectRows.length != 1){
$.messager.alert("消息提醒", "请选择一条数据进行操作!", "warning");
} else{
$("#editDialog").dialog("open");
}
});
//删除
$("#delete").click(function(){
var selectRows = $("#dataList").datagrid("getSelections");
var selectLength = selectRows.length;
if(selectLength == 0){
$.messager.alert("消息提醒", "请选择数据进行删除!", "warning");
} else{
var numbers = [];
$(selectRows).each(function(i, row){
numbers[i] = row.sn;
});
var ids = [];
$(selectRows).each(function(i, row){
ids[i] = row.id;
});
$.messager.confirm("消息提醒", "将删除与学生相关的所有数据(包括成绩),确认继续?", function(r){
if(r){
$.ajax({
type: "post",
url: "StudentServlet?method=DeleteStudent",
data: {sns: numbers, ids: ids},
success: function(msg){
if(msg == "success"){
$.messager.alert("消息提醒","删除成功!","info");
//刷新表格
$("#dataList").datagrid("reload");
$("#dataList").datagrid("uncheckAll");
} else{
$.messager.alert("消息提醒","删除失败!","warning");
return;
}
}
});
}
});
}
});
function preLoadClazz(){
$("#clazzList").combobox({
width: "150",
height: "25",
valueField: "id",
textField: "name",
multiple: false, //可多选
editable: false, //不可编辑
method: "post",
url: "ClazzServlet?method=getClazzList&t="+new Date().getTime()+"&from=combox",
onChange: function(newValue, oldValue){
//加载班级下的学生
//$('#dataList').datagrid("options").queryParams = {clazzid: newValue};
//$('#dataList').datagrid("reload");
}
});
}
//下拉框通用属性
$("#add_clazzList, #edit_clazzList").combobox({
width: "200",
height: "30",
valueField: "id",
textField: "name",
multiple: false, //可多选
editable: false, //不可编辑
method: "post",
});
$("#add_clazzList").combobox({
url: "ClazzServlet?method=getClazzList&t="+new Date().getTime()+"&from=combox",
onLoadSuccess: function(){
//默认选择第一条数据
var data = $(this).combobox("getData");;
$(this).combobox("setValue", data[0].id);
}
});
$("#edit_clazzList").combobox({
url: "ClazzServlet?method=getClazzList&t="+new Date().getTime()+"&from=combox",
onLoadSuccess: function(){
//默认选择第一条数据
var data = $(this).combobox("getData");
$(this).combobox("setValue", data[0].id);
}
});
//设置添加学生窗口
$("#addDialog").dialog({
title: "添加学生",
width: 650,
height: 460,
iconCls: "icon-add",
modal: true,
collapsible: false,
minimizable: false,
maximizable: false,
draggable: true,
closed: true,
buttons: [
{
text:'添加',
plain: true,
iconCls:'icon-user_add',
handler:function(){
var validate = $("#addForm").form("validate");
if(!validate){
$.messager.alert("消息提醒","请检查你输入的数据!","warning");
return;
} else{
var clazzid = $("#add_clazzList").combobox("getValue");
$.ajax({
type: "post",
url: "StudentServlet?method=AddStudent",
data: $("#addForm").serialize(),
success: function(msg){
if(msg == "success"){
$.messager.alert("消息提醒","添加成功!","info");
//关闭窗口
$("#addDialog").dialog("close");
//清空原表格数据
$("#add_number").textbox('setValue', "");
$("#add_name").textbox('setValue', "");
$("#add_sex").textbox('setValue', "男");
$("#add_phone").textbox('setValue', "");
$("#add_qq").textbox('setValue', "");
//重新刷新页面数据
$('#dataList').datagrid("options").queryParams = {clazzid: clazzid};
$('#dataList').datagrid("reload");
setTimeout(function(){
$("#clazzList").combobox('setValue', clazzid);
}, 100);
} else{
$.messager.alert("消息提醒","添加失败!","warning");
return;
}
}
});
}
}
},
{
text:'重置',
plain: true,
iconCls:'icon-reload',
handler:function(){
$("#add_number").textbox('setValue', "");
$("#add_name").textbox('setValue', "");
$("#add_phone").textbox('setValue', "");
$("#add_qq").textbox('setValue', "");
//重新加载年级
$("#add_gradeList").combobox("clear");
$("#add_gradeList").combobox("reload");
}
},
]
});
//设置编辑学生窗口
$("#editDialog").dialog({
title: "修改学生信息",
width: 650,
height: 460,
iconCls: "icon-edit",
modal: true,
collapsible: false,
minimizable: false,
maximizable: false,
draggable: true,
closed: true,
buttons: [
{
text:'提交',
plain: true,
iconCls:'icon-user_add',
handler:function(){
var validate = $("#editForm").form("validate");
var clazzid = $("#edit_clazzList").combobox("getValue");
if(!validate){
$.messager.alert("消息提醒","请检查你输入的数据!","warning");
return;
} else{
$.ajax({
type: "post",
url: "StudentServlet?method=EditStudent&t="+new Date().getTime(),
data: $("#editForm").serialize(),
success: function(msg){
if(msg == "success"){
$.messager.alert("消息提醒","更新成功!","info");
//关闭窗口
$("#editDialog").dialog("close");
//刷新表格
$('#dataList').datagrid("options").queryParams = {clazzid: clazzid};
$("#dataList").datagrid("reload");
$("#dataList").datagrid("uncheckAll");
setTimeout(function(){
$("#clazzList").combobox('setValue', clazzid);
}, 100);
} else{
$.messager.alert("消息提醒","更新失败!","warning");
return;
}
}
});
}
}
},
{
text:'重置',
plain: true,
iconCls:'icon-reload',
handler:function(){
//清空表单
$("#edit_name").textbox('setValue', "");
$("#edit_sex").textbox('setValue', "男");
$("#edit_phone").textbox('setValue', "");
$("#edit_qq").textbox('setValue', "");
$("#edit_gradeList").combobox("clear");
$("#edit_gradeList").combobox("reload");
}
}
],
onBeforeOpen: function(){
var selectRow = $("#dataList").datagrid("getSelected");
//设置值
$("#edit_name").textbox('setValue', selectRow.name);
$("#edit_sex").textbox('setValue', selectRow.sex);
$("#edit_mobile").textbox('setValue', selectRow.mobile);
$("#edit_qq").textbox('setValue', selectRow.qq);
$("#edit_photo").attr("src", "PhotoServlet?method=getPhoto&type=2&sid="+selectRow.id);
$("#edit-id").val(selectRow.id);
$("#set-photo-id").val(selectRow.id);
var clazzid = selectRow.clazzId;
setTimeout(function(){
$("#edit_clazzList").combobox('setValue', clazzid);
}, 100);
}
});
//搜索按钮监听事件
$("#search-btn").click(function(){
$('#dataList').datagrid('load',{
studentName: $('#search_student_name').val(),
clazzid: $("#clazzList").combobox('getValue') == '' ? 0 : $("#clazzList").combobox('getValue')
});
});
});
//上传图片按钮事件
$("#upload-photo-btn").click(function(){
});
function uploadPhoto(){
var action = $("#uploadForm").attr('action');
var pos = action.indexOf('sid');
if(pos != -1){
action = action.substring(0,pos-1);
}
$("#uploadForm").attr('action',action+'&sid='+$("#set-photo-id").val());
$("#uploadForm").submit();
setTimeout(function(){
var message = $(window.frames["photo_target"].document).find("#message").text();
$.messager.alert("消息提醒",message,"info");
$("#edit_photo").attr("src", "PhotoServlet?method=getPhoto&sid="+$("#set-photo-id").val());
}, 1500)
}
</script>
</head>
<body>
<!-- 学生列表 -->
<table id="dataList" cellspacing="0" cellpadding="0"></table>
<!-- 工具栏 -->
<div id="toolbar">
<!-- 编辑 -->
<div style="float: left;"><a id="edit" href="javascript:;" class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:true">修改</a></div>
<div style="float: left;" class="datagrid-btn-separator"></div>
<!-- 搜索姓名班级 -->
<div style="float: left;margin-top:4px;" class="datagrid-btn-separator" > 姓名:<input id="search_student_name" class="easyui-textbox" name="search_student_name" /></div>
<div style="margin-left: 10px;margin-top:4px;" >班级:<input id="clazzList" class="easyui-textbox" name="clazz" />
<a id="search-btn" href="javascript:;" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true">搜索</a>
</div>
</div>
<!-- 添加学生窗口 -->
<!-- 修改学生窗口 -->
<div id="editDialog" style="padding: 10px">
<div style="float: right; margin: 20px 20px 0 0; width: 200px; border: 1px solid #EBF3FF">
<img id="edit_photo" alt="照片" style="max-width: 200px; max-height: 400px;" title="照片" src="" />
<!-- 修改学生窗口 -->
<!-- enctype文件以二进制的形式上传,这样可以实现多种类型的文件上传。 -->
<form id="uploadForm" method="post" enctype="multipart/form-data" action="PhotoServlet?method=SetPhoto" target="photo_target">
<!-- StudentServlet?method=SetPhoto -->
<input type="hidden" name="sid" id="set-photo-id">
<input class="easyui-filebox" name="photo" data-options="prompt:'选择照片'" style="width:200px;">
<input id="upload-photo-btn" onClick="uploadPhoto()" class="easyui-linkbutton" style="width: 50px; height: 24px;" type="button" value="上传"/>
</form>
</div>
<form id="editForm" method="post">
<input type="hidden" name="id" id="edit-id">
<table cellpadding="8" >
<tr>
<td>姓名:</td>
<td><input id="edit_name" style="width: 200px; height: 30px;" class="easyui-textbox" type="text" name="name" data-options="required:true, missingMessage:'请填写姓名'" /></td>
</tr>
<tr>
<td>性别:</td>
<td><select id="edit_sex" class="easyui-combobox" data-options="editable: false, panelHeight: 50, width: 60, height: 30" name="sex"><option value="男">男</option><option value="女">女</option></select></td>
</tr>
<tr>
<td>电话:</td>
<td><input id="edit_mobile" style="width: 200px; height: 30px;" class="easyui-textbox" type="text" name="mobile" validType="mobile" /></td>
</tr>
<tr>
<td>QQ:</td>
<td><input id="edit_qq" style="width: 200px; height: 30px;" class="easyui-textbox" type="text" name="qq" validType="number" /></td>
</tr>
<tr>
<td>班级:</td>
<td><input id="edit_clazzList" style="width: 200px; height: 30px;" class="easyui-textbox" name="clazzid" /></td>
</tr>
</table>
</form>
</div>
<!-- 提交表单处理iframe框架 -->
<iframe id="photo_target" name="photo_target"></iframe>
personalView.jsp系统设置(更改密码)之前已经在SystmServlet写过学生端的更该密码
$(function() {
//修改密码窗口
$("#passwordDialog").dialog({
title: "修改密码",
width: 500,
height: 300,
iconCls: "icon-add",
modal: true,
collapsible: false,
minimizable: false,
maximizable: false,
draggable: true,
closed: true,
buttons: [
{
text:'提交',
iconCls:'icon-user_add',
handler:function(){
var validate = $("#editPassword").form("validate");
if(!validate){
$.messager.alert("消息提醒","根据右侧提示请检查你输入的数据!","warning");
return;
} else{
$.ajax({
type: "post",
url: "SystemServlet?method=EditPasswod&t="+new Date().getTime(),
data: $("#editPassword").serialize(),
success: function(msg){
if(msg == "success"){
$.messager.alert("消息提醒","修改成功,将重新登录","info")
setTimeout(function(){
top.location.href = "LoginServlet?method=logout";
}, 1000);
}else{
$.messager.alert("消息提醒",msg,"error")
}
}
});
}
}
},
{
text:'重置',
iconCls:'icon-reload',
handler:function(){
//清空表单
$("#old_password").textbox('setValue', "");
$("#new_password").textbox('setValue', "");
$("#re_password").textbox('setValue', "");
}
}
],
})
//设置编辑学生窗口
$("#editDialog").dialog({
title: "修改密码",
width: 500,
height: 400,
fit: true,
modal: false,
noheader: true,
collapsible: false,
minimizable: false,
maximizable: false,
draggable: true,
closed: false,
toolbar: [
{
text:'修改密码',
plain: true,
iconCls:'icon-password',
handler:function(){
$("#passwordDialog").dialog("open");
}
}
],
});
setTimeout(function(){
$("#passwordDialog").dialog("open");
},1000);
})
</script>
</head>
<body>
<div id="editDialog" style="padding: 20px;">
</div>
<!-- 修改密码窗口 -->
<div id="passwordDialog" style="padding: 20px">
<form id="editPassword">
<table cellpadding="8" >
<tr>
<td>原密码:</td>
<td>
<input id="old_password" name="password" style ="width: 200px; height: 30px;" class="easyui-textbox" type="password" data-options="required:true, missingMessage:'请输入原密码'" />
</td>
</tr>
<tr>
<td>新密码:</td>
<td>
<input id="new_password" style="width: 200px; height: 30px;" class="easyui-textbox" type="password" validType="password" name="newpassword" data-options="required:true, missingMessage:'请输入新密码'" />
</td>
</tr>
<tr>
<td>新密码:</td>
<td><input id="re_password" style="width: 200px; height: 30px;" class="easyui-textbox" type="password" validType="equals['#new_password']" data-options="required:true, missingMessage:'再次输入密码'" /></td>
</tr>
</table>
</form>
</div>
</body>
</html>
**
更多推荐



所有评论(0)