源代码及数据库获取链接:
https://download.csdn.net/download/qq_45968259/12605498
注:本文章仅供参考和学习,由于开发时间较短,系统存在一些漏洞和不合理之处,可以下载后自行修改完善。项目导入到eclipse中可能会因为JDK,tomcat版本不一致报错,可以自行新建一个项目将本项目文件粘贴到新项目中即可。如果出现乱码可能是英文编码方式不一致,可以修改一下项目的编码方式,本项目使用的编码方式为UTF-8。
本系统基于MVC模式开发,系统设计采用了面向对象编程思想,系统开发选择了Eclipse作为集成开发环境,使用了JSP和Java语言编写程序;前端使用HTML+CSS+JavaScript技术设计开发页面;后台数据库使用MySQL5.6.26。该系统所需要的运行环境如下:
1.客户端:360浏览器或者其他常用浏览器;
2.服务器端:安装JVM及MySQL数据库。
1.MVC模式
2.JSP技术
3.JDBC(Java Data Base Connectivity)技术
本系统基于MVC模式设计和开发的,在MVC模式中,三个层各施其职,所以如果一旦哪一层的需求发生了变化,就只需要更改相应的层中的代码而不会影响到其它层中的代码,有利于实现各施其职,互不干涉。同时由于按层把系统分开,有利于开发人员之间的任务分工。分层后降低了层与层之间的依赖有利于组件的重用和代码的标准化开发。
在功能设计上,系统包含前台和后台两大部分功能,其中前台主要按照用户权限实现用户信息查询查询、修改密码功能、学生信息查询功能、教师信息查询功能、课程信息查询功能、选课信息查询功能和成绩信息查询功能。其中学生可以查询其用户信息,个人信息,课程信息,选课信息和成绩信息。教师可以查询其用户信息,个人信息,学生信息,课程信息,成绩信息和选课信息。同时教师还可以对学生信息和成绩信息进行查询、添加、修改、删除、批量删除等操作。后台主要实现学生信息管理功能,教师信息管理功能,课程信息管理功能,成绩信息管理功能和选课信息管理功能这五大功能模块。管理员可以在学生信息模块、教师信息模块、课程信息模块、选课信息模块和成绩信息模块中进行查询,添加,修改,批量删除等操作。在学生信息管理模块中,管理员可以输入学号查询指定学生信息。在教师信息管理模块中,管理员可以输入教师号查询指定教师信息。在成绩信息管理模块中,管理员可以修改学生成绩并将成绩信息暂存。在课程信息管理模块中,管理员可以以输入课程号查询指定课程信息。在选课信息管理模块中,管理员可以可以以输入教师号或课程号查询指定选课信息。
学生成绩管理系统数据库共包含六个表,包括用户信息表、学生信息表、教师信息表、课程信息表、选课信息表、成绩信息表。
用户信息表的结构、表字段的数据类型及相关说明如表2-1所示:
1.登录界面
1.DBManager公共类
package com.dqpi.Util;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import com.mysql.jdbc.Statement;
public class DBManager {
Connection con;
String driver = "com.mysql.jdbc.Driver";
String uri = "jdbc:mysql://localhost:3306/studnetgrade?characterEncoding=utf8";
String user = "root";
String password = "";
ResultSet rs = null;
Statement st = null;
public DBManager(){
this.con = this.getConnection();
}
/*
* 作为连接数据库的类使用
*
* */
private Connection getConnection() {
try {
Class.forName(driver);
con = DriverManager.getConnection(uri,user,password);
if (!con.equals(null)) {
System.out.println("数据库连接成功");
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
System.out.println("你的驱动错误");
} catch (SQLException e) {
e.printStackTrace();
System.out.println("你的连接错误");
}
return con;
}
/*
* 查询操作
*
* */
public ResultSet executeQuery(String sql) {
try {
st = (Statement) con.createStatement();
rs = st.executeQuery(sql);
} catch (SQLException e) {
e.printStackTrace();
System.out.println("SQL语句执行错误");
}
return rs;
}
/*
* CUD操作
*
* */
public int executeUpdate(String sql) {
int cont = 0;
try {
st = (Statement) con.createStatement();
cont = st.executeUpdate(sql);
} catch (SQLException e) {
e.printStackTrace();
System.out.println("SQL语句执行CUD错误");
}
return cont;
}
/*
* 关闭资源
*
* */
//查询关闭
public void Close(){
try {
rs.close();
st.close();
con.close();
} catch (SQLException e) {
System.out.println("关闭失败");
}
}
//删除关闭
public void Close1(){
try {
st.close();
con.close();
} catch (SQLException e) {
System.out.println("关闭失败");
}
}
}
2.com.dqpi.Model包下的类
2.1 Course.java
package com.dqpi.Model;
public class Course {
private String Cno;
private String Cname;
private int Cgrade;
private int Ctime;
private String type;
public String getCno() {
return Cno;
}
public void setCno(String cno) {
Cno = cno;
}
public String getCname() {
return Cname;
}
public void setCname(String cname) {
Cname = cname;
}
public int getCgrade() {
return Cgrade;
}
public void setCgrade(int cgrade) {
Cgrade = cgrade;
}
public int getCtime() {
return Ctime;
}
public void setCtime(int ctime) {
Ctime = ctime;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
}
2.2 SC.java
package com.dqpi.Model;
public class SC {
private String Sno;
private int SCg;
private String Cno;
public String getSno() {
return Sno;
}
public void setSno(String sno) {
Sno = sno;
}
public int getSCg() {
return SCg;
}
public void setSCg(int sCg) {
SCg = sCg;
}
public String getCno() {
return Cno;
}
public void setCno(String cno) {
Cno = cno;
}
}
2.3 Student.java
package com.dqpi.Model;
public class Student {
private String Sno;
private String Sname;
private String Ssex;
private int Sage;
private String Sdept;
private String Clno;
public String getSno() {
return Sno;
}
public void setSno(String sno) {
Sno = sno;
}
public String getSname() {
return Sname;
}
public void setSname(String sname) {
Sname = sname;
}
public String getSsex() {
return Ssex;
}
public void setSsex(String ssex) {
Ssex = ssex;
}
public int getSage() {
return Sage;
}
public void setSage(int sage) {
Sage = sage;
}
public String getSdept() {
return Sdept;
}
public void setSdept(String sdept) {
Sdept = sdept;
}
public String getClno() {
return Clno;
}
public void setClno(String clno) {
Clno = clno;
}
}
2.4 StudentCourse.java
package com.dqpi.Model;
public class StudentCourse {
public String getSno() {
return Sno;
}
public void setSno(String sno) {
Sno = sno;
}
public String getSname() {
return Sname;
}
public void setSname(String sname) {
Sname = sname;
}
public String getCno() {
return Cno;
}
public void setCno(String cno) {
Cno = cno;
}
public String getCname() {
return Cname;
}
public void setCname(String cname) {
Cname = cname;
}
public int getCgrade() {
return Cgrade;
}
public void setCgrade(int cgrade) {
Cgrade = cgrade;
}
public String getTeacher() {
return Teacher;
}
public void setTeacher(String teacher) {
Teacher = teacher;
}
private String Sno;
private String Sname;
private String Cno;
private String Cname;
private int Cgrade;
private String Teacher;
}
2.5 TC.java
package com.dqpi.Model;
public class TC {
private String Stno;
private String Cno;
private String Clno;
public String getStno() {
return Stno;
}
public void setStno(String stno) {
Stno = stno;
}
public String getCno() {
return Cno;
}
public void setCno(String cno) {
Cno = cno;
}
public String getClno() {
return Clno;
}
public void setClno(String clno) {
Clno = clno;
}
}
2.6 Teacher.java
package com.dqpi.Model;
public class Teacher {
private String Stno;
private String Stname;
private String Stsex;
private int Stage;
private String Sto;
public String getStno() {
return Stno;
}
public void setStno(String stno) {
Stno = stno;
}
public String getStname() {
return Stname;
}
public void setStname(String stname) {
Stname = stname;
}
public String getStsex() {
return Stsex;
}
public void setStsex(String stsex) {
Stsex = stsex;
}
public int getStage() {
return Stage;
}
public void setStage(int stage) {
Stage = stage;
}
public String getSto() {
return Sto;
}
public void setSto(String sto) {
Sto = sto;
}
}
2.7 TeacherCourse.java
package com.dqpi.Model;
public class TeacherCourse {
public String getStno() {
return Stno;
}
public void setStno(String stno) {
Stno = stno;
}
public String getStname() {
return Stname;
}
public void setStname(String stname) {
Stname = stname;
}
public String getCno() {
return Cno;
}
public void setCno(String cno) {
Cno = cno;
}
public String getCname() {
return Cname;
}
public void setCname(String cname) {
Cname = cname;
}
public String getClno() {
return Clo;
}
public void setClno(String clno) {
Clo = clno;
}
private String Stno;
private String Stname;
private String Cno;
private String Cname;
private String Clo;
}
2.8 User.java
package com.dqpi.Model;
public class User {
private String Susername;
private String Spassword;
private String Sno;
private String SID;
public String getSusername() {
return Susername;
}
public void setSusername(String susername) {
Susername = susername;
}
public String getSpassword() {
return Spassword;
}
public void setSpassword(String spassword) {
Spassword = spassword;
}
public String getSno() {
return Sno;
}
public void setSno(String sno) {
Sno = sno;
}
public String getSID() {
return SID;
}
public void setSID(String sID) {
SID = sID;
}
}
3.com.dqpi.Service包下的Userservlet类
package com.dqpi.Service;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.servlet.jsp.JspApplicationContext;
import javax.websocket.Session;
import org.apache.jasper.tagplugins.jstl.core.If;
import org.omg.CORBA.PUBLIC_MEMBER;
import com.dqpi.Model.*;
import com.dqpi.UserDao.UserDAOI;
import com.dqpi.UserDao.Imp.UserDaoimp;
public class Userservlet extends HttpServlet{
public static HttpSession session1=null;
public static HttpSession session2=null;
public List<StudentCourse> TimeStudent=new ArrayList<StudentCourse>();
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String jsp=req.getParameter("jsp");
session1 = req.getSession();
if(jsp.equals("login")){
String rand =session1.getAttribute("code").toString();
String input = req.getParameter("code");
String message=null;
if(rand.equals(input)){
String usertype = req.getParameter("usertype");
session1.setAttribute("usertype", usertype);
String name=req.getParameter("name");
session1.setAttribute("name", name);
name=new String(name.getBytes("iso-8859-1"),"utf-8");
String password=req.getParameter("password");
session1.setAttribute("password", password);
System.out.println(name+"\t"+password+"\t"+usertype);
UserDAOI userDAOI = new UserDaoimp();
List<User> list = new ArrayList<>();
list = userDAOI.Sselect(name,password,usertype);
System.out.println("1");
if(list.size()!=0){
System.out.println(3);
System.out.println(usertype);
session1.setAttribute("userList", list);
if(usertype.equals("student")){
resp.sendRedirect("main/index.jsp");
}
if(usertype.equals("teacher")){
resp.sendRedirect("main/index(teacher).jsp");
}
if(usertype.equals("manager")){
resp.sendRedirect("main/index(manager).jsp");
}
}
else{
message="用户名或密码输入错误";
session1.setAttribute("message",message);
resp.sendRedirect("login.jsp");
}
System.out.println("2");
}else{
message="验证码出错";
System.out.println("验证码出错");
session1.setAttribute("message",message);
resp.sendRedirect("login.jsp");
}
}
if(jsp.equals("updatepassword")){
String crudper=null;
String password=(String)session1.getAttribute("password");
String username=(String)session1.getAttribute("name");
String mpass=req.getParameter("mpass");
if(password.equals(mpass)){
crudper="修改成功";
session1.setAttribute("crudper", crudper);
String newpass=req.getParameter("newpass");
session1.setAttribute("password",newpass);
UserDAOI user=new UserDaoimp();
user.resetInfo(username,password,newpass);
resp.sendRedirect("personnew.jsp");
}
else{
crudper="原始密码不同";
session1.setAttribute("crudper", crudper);
resp.sendRedirect("personnew.jsp");
}
}
System.out.println(jsp);
if(jsp.equals("TeacherManagerUpdate")){
String Stno=req.getParameter("mTeacherStno");
String Stname=req.getParameter("mTeacherStname");
Stname=new String(Stname.getBytes("iso-8859-1"),"utf-8");
String Stsex=req.getParameter("mTeacherSsex");
Stsex=new String(Stsex.getBytes("iso-8859-1"),"utf-8");
String Ssage=req.getParameter("mTeacherSage");
String Sto=req.getParameter("mTeacherSto");
Sto=new String(Sto.getBytes("iso-8859-1"),"utf-8");
UserDAOI user=new UserDaoimp();
String message=user.insertTeacherManager(Stno,Stname,Stsex,Ssage,Sto);
System.out.println(message);
session1.setAttribute("TeacherManagerUpdate.message", message);
UserDAOI user2=new UserDaoimp();
List<Teacher> StudentCourse = new ArrayList<>();
StudentCourse =user2.TeacherInformation();
session2.setAttribute("TeacherInformation",StudentCourse);
resp.sendRedirect("TeacherInformation.jsp");
}
if(jsp.equals("Student_update_Information")){
String Sno=req.getParameter("Sno");
String Sname=req.getParameter("mTeacherStno");
String Ssex=req.getParameter("mTeacherStname");
Sname=new String(Sname.getBytes("iso-8859-1"),"utf-8");
String Sage=req.getParameter("mTeacherSsex");
Ssex=new String(Ssex.getBytes("iso-8859-1"),"utf-8");
String Sdept=req.getParameter("mTeacherSage");
String Clno=req.getParameter("mTeacherSto");
Sdept=new String(Sdept.getBytes("iso-8859-1"),"utf-8");
UserDAOI user=new UserDaoimp();
String message=user.updateStudentInformation(Sno,Sname,Ssex,Sage,Sdept,Clno);
System.out.println(message);
session1.setAttribute("updateStudentInformatio", message);
UserDAOI user2=new UserDaoimp();
System.out.println(1);
List<Student> StudentCourse = new ArrayList<>();
StudentCourse =user2.index_teacher_StudentInformation();
session2.setAttribute("index_teacher_StudentInformation",StudentCourse);
resp.sendRedirect("CrudStudent.jsp");
}
if(jsp.equals("Student_update_Course")){
String Cno=req.getParameter("Stno");
String Cname=req.getParameter("mTeacherStno");
String Ctime=req.getParameter("mTeacherStname");
Cname=new String(Cname.getBytes("iso-8859-1"),"utf-8");
String Cgrade=req.getParameter("mTeacherSsex");
String Ctype=req.getParameter("mTeacherSage");
Ctype=new String(Ctype.getBytes("iso-8859-1"),"utf-8");
UserDAOI user=new UserDaoimp();
String message=user.updateCourse(Cno,Cname,Cgrade,Ctime,Ctype);
System.out.println(message);
session1.setAttribute("updateCourse", message);
UserDAOI user2=new UserDaoimp();
List<Course> StudentCourse = new ArrayList<>();
StudentCourse =user2.StudentSelectCourse();
session2.setAttribute("Teacher.Course",StudentCourse);
resp.sendRedirect("Course.jsp");
}
if(jsp.equals("Teacher_update_Teacher")){
String Stno=req.getParameter("Sno");
String Stname=req.getParameter("mTeacherStno");
String Stsex=req.getParameter("mTeacherStname");
Stname=new String(Stname.getBytes("iso-8859-1"),"utf-8");
String Stage=req.getParameter("mTeacherSsex");
Stsex=new String(Stsex.getBytes("iso-8859-1"),"utf-8");
String Sto=req.getParameter("mTeacherSage");
Sto=new String(Sto.getBytes("iso-8859-1"),"utf-8");
UserDAOI user=new UserDaoimp();
String message=user.updateTeacher(Stno,Stname,Stsex,Stage,Sto);
System.out.println(message);
session1.setAttribute("updateStudentInformatio", message);
UserDAOI user2=new UserDaoimp();
List<Teacher> StudentCourse = new ArrayList<>();
StudentCourse =user2.TeacherInformation();
session2.setAttribute("TeacherInformation",StudentCourse);
resp.sendRedirect("TeacherInformation.jsp");
}
if(jsp.equals("Teacher_update_Teacher1")){
String Stno=req.getParameter("Sno");
System.out.println(Stno);
String Stname=req.getParameter("mTeacherStno");
String Stsex=req.getParameter("mTeacherStname");
Stname=new String(Stname.getBytes("iso-8859-1"),"utf-8");
String Stage=req.getParameter("mTeacherSsex");
Stsex=new String(Stsex.getBytes("iso-8859-1"),"utf-8");
String Sto=req.getParameter("mTeacherSage");
Sto=new String(Sto.getBytes("iso-8859-1"),"utf-8");
UserDAOI user=new UserDaoimp();
String message=user.updateTeacher(Stno,Stname,Stsex,Stage,Sto);
System.out.println(message);
session1.setAttribute("updateStudentInformatio1", message);
UserDAOI user2=new UserDaoimp();
List<Teacher> index_teacher_user=new ArrayList<>();
index_teacher_user=user2.index_teacher_user2(Stno);
session2.setAttribute("index_teacher_user",index_teacher_user);
resp.sendRedirect("TeacherSelect.jsp");
}
if(jsp.equals("Student_update_Select")){
String Stno=req.getParameter("Sno");
String OCno=req.getParameter("Stname");
String Cno=req.getParameter("mTeacherStno");
String Clo=req.getParameter("mTeacherStname");
UserDAOI user=new UserDaoimp();
String message=user.updateSelect(Stno,OCno,Cno,Clo);
UserDAOI user2=new UserDaoimp();
List<TeacherCourse> StudentCourse = new ArrayList<>();
StudentCourse =user2.Teacher_SelectCourse();
session2.setAttribute("Teacher_SelectCourse",StudentCourse);
resp.sendRedirect("SelectCourse.jsp");
}
if(jsp.equals("Student_update_Grade")){
String Sno=req.getParameter("Sno");
String Cno=req.getParameter("Cno");
String Sname=req.getParameter("mTeacherStno");
String Cname=req.getParameter("mTeacherStname");
Sname=new String(Sname.getBytes("iso-8859-1"),"utf-8");
Cname=new String(Cname.getBytes("iso-8859-1"),"utf-8");
String Scg=req.getParameter("mTeacherSage");
UserDAOI user=new UserDaoimp();
user.updateGradeAll(Sno,Cno,Sname,Cname,Scg);
resp.sendRedirect("Grade.jsp");
}
if(jsp.equals("AddStudentInformation")){
String Sno=req.getParameter("mTeacherStno");
String Sname=req.getParameter("mTeacherStname");
Sname=new String(Sname.getBytes("iso-8859-1"),"utf-8");
String Ssex=req.getParameter("mTeacherSsex");
Ssex=new String(Ssex.getBytes("iso-8859-1"),"utf-8");
String Sage=req.getParameter("mTeacherSage");
String Sdept=req.getParameter("mTeacherSto");
Sdept=new String(Sdept.getBytes("iso-8859-1"),"utf-8");
String Clno=req.getParameter("mClo");
UserDAOI user=new UserDaoimp();
String message=user.AddStudentInformation(Sno,Sname,Ssex,Sage,Sdept,Clno);
System.out.println(message);
session1.setAttribute("updateStudentInformatio", message);
UserDAOI user2=new UserDaoimp();
System.out.println(1);
List<Student> StudentCourse = new ArrayList<>();
StudentCourse =user2.index_teacher_StudentInformation();
session2.setAttribute("index_teacher_StudentInformation",StudentCourse);
resp.sendRedirect("CrudStudent.jsp");
}
if(jsp.equals("AddCourse")){
String Cno=req.getParameter("mTeacherStno");
String Cname=req.getParameter("mTeacherStname");
String Ctime=req.getParameter("mTeacherSsex");
Cname=new String(Cname.getBytes("iso-8859-1"),"utf-8");
String Cgrade=req.getParameter("mTeacherSage");
String Ctype=req.getParameter("mTeacherSto");
Ctype=new String(Ctype.getBytes("iso-8859-1"),"utf-8");
UserDAOI user=new UserDaoimp();
String message=user.AddCourse(Cno,Cname,Cgrade,Ctime,Ctype);
System.out.println(message);
session1.setAttribute("updateCourse", message);
UserDAOI user2=new UserDaoimp();
List<Course> StudentCourse = new ArrayList<>();
StudentCourse =user2.StudentSelectCourse();
session2.setAttribute("Teacher.Course",StudentCourse);
resp.sendRedirect("Course.jsp");
}
if(jsp.equals("AddSelect")){
String Cname=req.getParameter("mTeacherStno");
String Ctime=req.getParameter("mTeacherStname");
String Cgrade=req.getParameter("mTeacherSsex");
UserDAOI user=new UserDaoimp();
String message=user.AddSelect(Cname,Ctime,Cgrade);
resp.sendRedirect("AddSelect.jsp");
}
if(jsp.equals("Student_Add_Grade")){
String Sno=req.getParameter("mSo");
String Cno=req.getParameter("mCno");
String Sname=req.getParameter("mTeacherStno");
String Cname=req.getParameter("mTeacherStname");
Sname=new String(Sname.getBytes("iso-8859-1"),"utf-8");
Cname=new String(Cname.getBytes("iso-8859-1"),"utf-8");
String Scg=req.getParameter("mTeacherSage");
UserDAOI user=new UserDaoimp();
user.AddGradeAll(Sno,Cno,Sname,Cname,Scg);
resp.sendRedirect("Grade.jsp");
}
if(jsp.equals("TimeAddGrade")){
StudentCourse Student=new StudentCourse();
String Sno=req.getParameter("mSno");
String Cno=req.getParameter("mCno");
String Sname=req.getParameter("mTeacherStno");
String Cname=req.getParameter("mTeacherStname");
Sname=new String(Sname.getBytes("iso-8859-1"),"utf-8");
Cname=new String(Cname.getBytes("iso-8859-1"),"utf-8");
int Scg=Integer.getInteger(req.getParameter("mTeacherSage"));
Student.setSno(Sno);Student.setCno(Sno);Student.setSname(Sname);
Student.setCname(Cname);Student.setCgrade(Scg);
TimeStudent.add(Student);
this.getServletContext().setAttribute("TimeStudentGrade",TimeStudent);
resp.sendRedirect("Time.jsp");
}
}
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
System.out.println("jdsfadj");
String Ajsp=req.getParameter("Ajsp");
session2=req.getSession();
System.out.println(Ajsp);
if(Ajsp.equals("main.index")){
String name=(String)session1.getAttribute("name");
UserDAOI user=new UserDaoimp();
List<Student> StudentSelect = new ArrayList<>();
StudentSelect =user.Studentinformation(name);
session2.setAttribute("StudentSelect",StudentSelect);
resp.sendRedirect("../common/StudentSelect.jsp");
System.out.println("1");
}
if(Ajsp.equals("main.index.course")){
String name=(String)session1.getAttribute("name");
UserDAOI user=new UserDaoimp();
List<StudentCourse> StudentCourse = new ArrayList<>();
StudentCourse =user.Studentcourse(name);
String main_Index_message=null;
String type=req.getParameter("type");
session2.setAttribute("StudentCourse",StudentCourse);
if(type.equals("course")){
main_Index_message="课程";
}
if(type.equals("grade")){
main_Index_message="选课";
}
session2.setAttribute("main_Index_message",main_Index_message);
resp.sendRedirect("../course/Studentcourse.jsp");
System.out.println("1");
}
if(Ajsp.equals("main.index.select")){
UserDAOI user=new UserDaoimp();
List<Course> StudentSelectCourse = new ArrayList<>();
StudentSelectCourse=user.StudentSelectCourse();
session2.setAttribute("StudentSelectCourse",StudentSelectCourse);
resp.sendRedirect("../course/Course_Information.jsp");
System.out.println("1");
}
if(Ajsp.equals("index(teacher).user")){
String name=(String)session1.getAttribute("name");
UserDAOI user=new UserDaoimp();
List<Teacher> index_teacher_user=new ArrayList<>();
index_teacher_user=user.index_teacher_user(name);
session2.setAttribute("index_teacher_user",index_teacher_user);
resp.sendRedirect("../Teacher/TeacherSelect.jsp");
}
if(Ajsp.equals("index(teacher).StudentInformation")){
this.Student(req, resp);
}
if(Ajsp.equals("index(teacher).selectCourse")){
String name=(String)session1.getAttribute("name");
UserDAOI user=new UserDaoimp();
List<TeacherCourse> IndexTeacherSelectCourse = new ArrayList<>();
IndexTeacherSelectCourse =user.IndexTeacherSelectCourse(name);
session2.setAttribute("IndexTeacherSelectCourse",IndexTeacherSelectCourse);
resp.sendRedirect("../SelectCourse/Teacher.jsp");
System.out.println("1");
}
if(Ajsp.equals("CrudStudent")){
String idall = req.getParameter("idAll");
System.out.println(idall);
System.out.println(1);
String[] idone = idall.split(",");
for(String string:idone){
UserDAOI userDAOI = new UserDaoimp();
userDAOI.delete(string);
}
UserDAOI user=new UserDaoimp();
List<Student> StudentCourse = new ArrayList<>();
StudentCourse =user.index_teacher_StudentInformation();
session2.setAttribute("index_teacher_StudentInformation",StudentCourse);
resp.sendRedirect("CrudStudent.jsp");
}
if(Ajsp.equals("index(teacher).Student.Grade")){
this.StudentCourse(req, resp);
}
if(Ajsp.equals("Student.Grade")){
System.out.println("1");
String Sno=req.getParameter("sno");
System.out.println(Sno);
UserDAOI user=new UserDaoimp();
List<StudentCourse> StudentCourse = new ArrayList<>();
StudentCourse =user.Studentcourse1(Sno);
session2.setAttribute("Student.GradeAll",StudentCourse);
resp.sendRedirect("../Student/GradeAll.jsp");
}
if(Ajsp.equals("Student.Grade.delete")){
String idall = req.getParameter("idAll");
System.out.println(idall);
System.out.println(1);
String[] idone = idall.split(",");
for(String string:idone){
UserDAOI userDAOI = new UserDaoimp();
userDAOI.deleteAn(string);
}
UserDAOI user=new UserDaoimp();
List<StudentCourse> StudentCourse = new ArrayList<>();
StudentCourse =user.Studentcourse();
session2.setAttribute("IndexTeacherStudentGrade",StudentCourse);
resp.sendRedirect("../Student/Grade.jsp");
}
if(Ajsp.equals("GradeAlldelete")){
String idall = req.getParameter("idAll");
System.out.println(idall);
String[] idone =idall.split(",");
String[] Sno=new String[idone.length];
String[] Cno=new String[idone.length];
System.out.println(idone.length);
for(int i=0;i<idone.length;i++){
int leng=idone[i].indexOf(" ");
Sno[i]=idone[i].substring(0,leng);
Cno[i]=idone[i].substring(leng+1);
System.out.println(Sno[i]);
System.out.println(Cno[i]);
}
for(int i=0;i<idone.length;i++){
UserDAOI user=new UserDaoimp();
user.deleteAll(Sno[i],Cno[i]);
}
}
if(Ajsp.equals("TeacherInformation")){
UserDAOI user=new UserDaoimp();
List<Teacher> TeacherInformation = new ArrayList<>();
TeacherInformation=user.TeacherInformation();
session2.setAttribute("TeacherInformation",TeacherInformation);
resp.sendRedirect("../Teacher/TeacherInformation.jsp");
}
if(Ajsp.equals("Teacher.TeacherInformation")){
String idall = req.getParameter("idAll");
System.out.println(idall);
System.out.println(1);
String[] idone = idall.split(",");
for(String string:idone){
UserDAOI userDAOI = new UserDaoimp();
userDAOI.deleteTeacherInformation(string);
}
UserDAOI user=new UserDaoimp();
List<Teacher> StudentCourse = new ArrayList<>();
StudentCourse =user.TeacherInformation();
session2.setAttribute("TeacherInformation",StudentCourse);
resp.sendRedirect("TeacherInformation.jsp");
}
if(Ajsp.equals("index(manager).Course")){
UserDAOI user=new UserDaoimp();
List<Course> Teacher_Course = new ArrayList<>();
Teacher_Course=user.StudentSelectCourse();
session2.setAttribute("Teacher.Course",Teacher_Course);
resp.sendRedirect("../Teacher/Course.jsp");
}
if(Ajsp.equals("Teacher.Course")){
String idall = req.getParameter("idAll");
System.out.println(idall);
System.out.println(1);
String[] idone = idall.split(",");
for(String string:idone){
UserDAOI userDAOI = new UserDaoimp();
userDAOI.deleteTeacherCoures(string);
}
UserDAOI user=new UserDaoimp();
List<Course> StudentCourse = new ArrayList<>();
StudentCourse =user.StudentSelectCourse();
session2.setAttribute("Teacher.Course",StudentCourse);
resp.sendRedirect("Course.jsp");
}
if(Ajsp.equals("index(manager).SelectCourse")){
UserDAOI user=new UserDaoimp();
List<TeacherCourse> Teacher_SelectCourse = new ArrayList<>();
Teacher_SelectCourse=user.Teacher_SelectCourse();
session2.setAttribute("Teacher_SelectCourse",Teacher_SelectCourse);
resp.sendRedirect("../Teacher/SelectCourse.jsp");
}
if(Ajsp.equals("Teacher_Teacher_SelectCourse")){
String idall = req.getParameter("idAll");
System.out.println(idall);
String[] idone =idall.split(",");
String[] Sno=new String[idone.length];
String[] Cno=new String[idone.length];
System.out.println(idone.length);
for(int i=0;i<idone.length;i++){
int leng=idone[i].indexOf(" ");
Sno[i]=idone[i].substring(0,leng);
Cno[i]=idone[i].substring(leng+1);
System.out.println(Sno[i]);
System.out.println(Cno[i]);
}
for(int i=0;i<idone.length;i++){
UserDAOI user=new UserDaoimp();
user.deleteSelectCourse(Sno[i],Cno[i]);
}
UserDAOI user=new UserDaoimp();
List<TeacherCourse> StudentCourse = new ArrayList<>();
StudentCourse =user.Teacher_SelectCourse();
session2.setAttribute("Teacher_SelectCourse",StudentCourse);
resp.sendRedirect("SelectCourse.jsp");
}
if(Ajsp.equals("ManagerUpdateAjsp")){
String Stno=req.getParameter("mTeacherStno");
String Stname=req.getParameter("mTeacherStname");
Stname=new String(Stname.getBytes("iso-8859-1"),"utf-8");
String Stsex=req.getParameter("mTeacherSsex");
Stsex=new String(Stsex.getBytes("iso-8859-1"),"utf-8");
int Ssage=Integer.getInteger(req.getParameter("mTeacherSage"));
String Sto=req.getParameter("mTeacherSto");
Sto=new String(Sto.getBytes("iso-8859-1"),"utf-8");
Teacher user=new Teacher();
user.setStno(Stno);
user.setStno(Stname);
user.setStsex(Stsex);
user.setStage(Ssage);
user.setSto(Sto);
}
if(Ajsp.equals("Student.CrudStudent.Select")){
String Sno=req.getParameter("keywords");
UserDAOI user=new UserDaoimp();
List<Student> Student_CrudStudent_Select = new ArrayList<>();
Student_CrudStudent_Select =user.StudentinformationManager(Sno);
session2.setAttribute("index_teacher_StudentInformation",Student_CrudStudent_Select);
resp.sendRedirect("CrudStudent.jsp");
System.out.println("1");
}
if(Ajsp.equals("Teacher_SelectCourse_SelectAll")){
UserDAOI user=new UserDaoimp();
List<TeacherCourse> StudentCourse = new ArrayList<>();
StudentCourse =user.Teacher_SelectCourse();
session2.setAttribute("Teacher_SelectCourse",StudentCourse);
resp.sendRedirect("SelectCourse.jsp");
}
if(Ajsp.equals("Teacher_Course_SelectAll")){
UserDAOI user=new UserDaoimp();
List<Course> StudentCourse = new ArrayList<>();
StudentCourse =user.StudentSelectCourse();
session2.setAttribute("Teacher.Course",StudentCourse);
resp.sendRedirect("Course.jsp");
}
if(Ajsp.equals("Teacher_TeacherInformation_SelectAll")){
UserDAOI user=new UserDaoimp();
List<Teacher> StudentCourse = new ArrayList<>();
StudentCourse =user.TeacherInformation();
session2.setAttribute("TeacherInformation",StudentCourse);
resp.sendRedirect("TeacherInformation.jsp");
}
if(Ajsp.equals("Student_CrudStudent_SelectAll")){
UserDAOI user=new UserDaoimp();
System.out.println(1);
List<Student> StudentCourse = new ArrayList<>();
StudentCourse =user.index_teacher_StudentInformation();
session2.setAttribute("index_teacher_StudentInformation",StudentCourse);
resp.sendRedirect("CrudStudent.jsp");
}
if(Ajsp.equals("Teacher_TeacherInformation_Select")){
String Sno=req.getParameter("keywords");
UserDAOI user=new UserDaoimp();
List<Teacher> StudentCourse = new ArrayList<>();
StudentCourse =user.index_teacher_user2(Sno);
session2.setAttribute("TeacherInformation",StudentCourse);
resp.sendRedirect("TeacherInformation.jsp");
}
if(Ajsp.equals("Teacher_Course_Select")){
String Sno=req.getParameter("keywords");
UserDAOI user=new UserDaoimp();
System.out.println(Sno);
List<Course> StudentCourse = new ArrayList<>();
StudentCourse =user.Course(Sno);
session2.setAttribute("Teacher.Course",StudentCourse);
resp.sendRedirect("Course.jsp");
}
if(Ajsp.equals("Student_Grade_Select")){
String Sno=req.getParameter("keywords");
UserDAOI user=new UserDaoimp();
List<StudentCourse> StudentCourse = new ArrayList<>();
StudentCourse =user.StudentcourseSelect(Sno);
session2.setAttribute("IndexTeacherStudentGrade",StudentCourse);
resp.sendRedirect("Grade.jsp");
}
if(Ajsp.equals("Teacher_SelectCourse_Select")){
String Stno=req.getParameter("keywords");
String Cno=req.getParameter("keyword");
System.out.println(Stno);
UserDAOI user=new UserDaoimp();
List<TeacherCourse> StudentCourse = new ArrayList<>();
StudentCourse =user.IndexTeacherSelectCourse1(Stno,Cno);
session2.setAttribute("Teacher_SelectCourse",StudentCourse);
resp.sendRedirect("SelectCourse.jsp");
}
if(Ajsp.equals("TimeAddGrade")){
StudentCourse Student=new StudentCourse();
String Sno=req.getParameter("mSno");
String Cno=req.getParameter("mCno");
String Sname=req.getParameter("Sname");
String Cname=req.getParameter("Cname");
Sname=new String(Sname.getBytes("iso-8859-1"),"utf-8");
Cname=new String(Cname.getBytes("iso-8859-1"),"utf-8");
//int Scg=Integer.getInteger(req.getParameter("Scg"));
String Scg=req.getParameter("Scg");
System.out.println(Sno+Cno+Sname+Cname+Scg);
int Sscg=Integer.parseInt(Scg);
Student.setSno(Sno);Student.setCno(Cno);Student.setSname(Sname);
Student.setCname(Cname);Student.setCgrade(Sscg);
TimeStudent.add(Student);
System.out.println(TimeStudent.size());
for(int i=0;i<TimeStudent.size();i++){
System.out.println(((StudentCourse)TimeStudent.get(i)).getCno()+"\t"+((StudentCourse)TimeStudent.get(i)).getSno());
}
session2.setAttribute("TimeStudentGrade",TimeStudent);
resp.sendRedirect("GradeAll.jsp");
}
}
public void StudentCourse(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
UserDAOI user=new UserDaoimp();
List<StudentCourse> StudentCourse = new ArrayList<>();
StudentCourse =user.Studentcourse();
session2.setAttribute("IndexTeacherStudentGrade",StudentCourse);
resp.sendRedirect("../Student/Grade.jsp");
}
public void Student(HttpServletRequest req, HttpServletResponse resp)throws ServletException, IOException{
UserDAOI user=new UserDaoimp();
List<Student> index_teacher_StudentInformation = new ArrayList<>();
index_teacher_StudentInformation=user.index_teacher_StudentInformation();
session2.setAttribute("index_teacher_StudentInformation",index_teacher_StudentInformation);
resp.sendRedirect("../Student/CrudStudent.jsp");
}
}
4.com.dqpi.UserDao包下的接口UserDAOI
package com.dqpi.UserDao;
import java.util.List;
import com.dqpi.Model.*;
public interface UserDAOI {
public List<User> Sselect(String name,String password,String usertype);
public List<Student> Studentinformation(String name);
public List<Student> StudentinformationManager(String name);
public List<StudentCourse> Studentcourse(String name);
public List<StudentCourse> Studentcourse1(String name);
public List<StudentCourse> Studentcourse();
public List<StudentCourse> StudentcourseSelect(String name);
public List<TeacherCourse> IndexTeacherSelectCourse(String name);
public List<TeacherCourse> Teacher_SelectCourse();
public List<TeacherCourse> IndexTeacherSelectCourse1(String name);
public List<TeacherCourse> IndexTeacherSelectCourse1(String name,String b);
public List<Course> StudentSelectCourse();
public List<Course> Course(String name);
public List<Student> index_teacher_StudentInformation();
public List<Teacher> TeacherInformation();
public List<Teacher> index_teacher_user(String name);
public List<Teacher> index_teacher_user2(String name);
public void resetInfo(String username,String password,String mpass);
public void delete(String string);
public void deleteAll(String string,String x);
public void deleteAn(String string);
public void deleteTeacherInformation(String string);
public void deleteTeacherCoures(String string);
public void deleteSelectCourse(String string,String Cno)
;
public String insertTeacherManager(String a,String b,String c,String d,String f);
public String updateStudentInformation(String a,String b,String c,String d,String e,String f);
public String updateCourse(String Cno,String Cname,String Cgrade,String Ctime,String Ctype);
public String updateTeacher(String a,String b,String c,String d,String e);
public String updateSelect(String Stno,String OCno,String Cno,String Clo);
public String AddStudentInformation(String a,String b,String c,String d,String e,String f);
public void updateGradeAll(String a,String b,String c,String e,String f);
public String AddCourse(String Cno,String Cname,String Cgrade,String Ctime,String Ctype);
public String AddSelect(String Stno,String Cno,String Clno);
public void AddGradeAll(String a,String b,String c,String e,String f);
}
5.com.dqpi.UserDao.Imp包下接口UserDAOI的实现类UserDaoimp
package com.dqpi.UserDao.Imp;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import javax.print.DocFlavor.STRING;
import com.dqpi.Model.*;
import com.dqpi.UserDao.UserDAOI;
import com.dqpi.Util.DBManager;
public class UserDaoimp implements UserDAOI{
public List<User> Sselect(String name,String password,String usertype) {
DBManager db = new DBManager();
List<User> list = new ArrayList<User>();
String sql = "select * from Userperson where Susername='"+name+"' and Spassword='"+password+"' and Sno='"+usertype+"'";
System.out.println(sql);
ResultSet rs = db.executeQuery(sql);
try {
while (rs.next()) {
System.out.println(sql);
User user = new User();
user.setSusername(rs.getString("Susername").trim());
user.setSpassword(rs.getString("Spassword").trim());
user.setSno(rs.getString("Sno").trim());
user.setSID(rs.getString("SID").trim());
System.out.println(user.getSusername()+user.getSpassword()+user.getSno()+user.getSID());
list.add(user);
}
}
catch (SQLException e) {
System.out.println("失败");
}
db.Close();
return list;
}
public List<Student> Studentinformation(String name){
DBManager db = new DBManager();
List<Student> list = new ArrayList<Student>();
String sql ="select Student.Sno,Sname ,Ssex,Sage,Sdept,Clno from Userperson,Student where Userperson.SID=Student.Sno and Susername='"+name+"'";
System.out.println(sql);
ResultSet rs = db.executeQuery(sql);
try {
while (rs.next()){
Student user = new Student();
user.setSno(rs.getString("Sno").trim());
System.out.println(user.getSno());
user.setSname(rs.getString("Sname").trim());
System.out.println(user.getSname());
user.setSsex(rs.getString("Ssex"));
System.out.println(user.getSsex());
user.setSage(rs.getInt("Sage"));
System.out.println(user.getSage());
user.setSdept(rs.getString("Sdept"));
user.setClno(rs.getString("Clno"));
System.out.println(user.getSno()+"\t"+user.getSage()+"t"+user.getClno()+"\t"+user.getSdept()+"\t"+user.getSname()+user.getSsex());
list.add(user);
}
}
catch (SQLException e) {
System.out.println("失败");
}
db.Close();
return list;
}
public List<Student> StudentinformationManager(String name){
DBManager db = new DBManager();
List<Student> list = new ArrayList<Student>();
String sql ="select Sno,Sname ,Ssex,Sage,Sdept,Clno from Student where Sno='"+name+"'";
System.out.println(sql);
ResultSet rs = db.executeQuery(sql);
try {
while (rs.next()){
Student user = new Student();
user.setSno(rs.getString("Sno").trim());
System.out.println(user.getSno());
user.setSname(rs.getString("Sname").trim());
System.out.println(user.getSname());
user.setSsex(rs.getString("Ssex"));
System.out.println(user.getSsex());
user.setSage(rs.getInt("Sage"));
System.out.println(user.getSage());
user.setSdept(rs.getString("Sdept"));
user.setClno(rs.getString("Clno"));
System.out.println(user.getSno()+"\t"+user.getSage()+"t"+user.getClno()+"\t"+user.getSdept()+"\t"+user.getSname()+user.getSsex());
list.add(user);
}
}
catch (SQLException e) {
System.out.println("失败");
}
db.Close();
return list;
}
public List<StudentCourse> Studentcourse(String name){
DBManager db = new DBManager();
List<StudentCourse> list = new ArrayList<StudentCourse>();
String sql ="select Student.Sno,Sname ,Course.Cno,Cname,Stname,Scg "+
"from Userperson,Student,SC,Course,TC,Teacher "+
"where Userperson.SID=Student.Sno and Student.Sno=SC.Sno and SC.Cno=Course.Cno and Course.Cno=TC.Cno and TC.Stno=Teacher.Stno "
+"and Susername='"+name+"'";
System.out.println(sql);
ResultSet rs = db.executeQuery(sql);
try {
while (rs.next()){
StudentCourse user = new StudentCourse();
user.setSno(rs.getString("Sno").trim());
System.out.println(user.getSno());
user.setSname(rs.getString("Sname").trim());
System.out.println(user.getSname());
user.setCno(rs.getString("Cno"));
System.out.println(user.getCno());
user.setCname(rs.getString("Cname"));
System.out.println(user.getCname());
user.setTeacher(rs.getString("Stname"));
user.setCgrade(rs.getInt("Scg"));
list.add(user);
}
}
catch (SQLException e) {
System.out.println("失败");
}
db.Close();
return list;
}
public List<StudentCourse> Studentcourse1(String name){
DBManager db = new DBManager();
List<StudentCourse> list = new ArrayList<StudentCourse>();
String sql ="select Student.Sno,Sname ,Course.Cno,Cname,Stname,Scg "+
"from Student,SC,Course,TC,Teacher "+
"where Student.Sno=SC.Sno and SC.Cno=Course.Cno and Course.Cno=TC.Cno and TC.Stno=Teacher.Stno "
+"and Student.Sno='"+name+"'";
System.out.println(sql);
ResultSet rs = db.executeQuery(sql);
try {
while (rs.next()){
StudentCourse user = new StudentCourse();
user.setSno(rs.getString("Sno").trim());
System.out.println(user.getSno());
user.setSname(rs.getString("Sname").trim());
System.out.println(user.getSname());
user.setCno(rs.getString("Cno"));
System.out.println(user.getCno());
user.setCname(rs.getString("Cname"));
System.out.println(user.getCname());
user.setTeacher(rs.getString("Stname"));
user.setCgrade(rs.getInt("Scg"));
list.add(user);
}
}
catch (SQLException e) {
System.out.println("失败");
}
db.Close();
return list;
}
public List<TeacherCourse> IndexTeacherSelectCourse1(String name,String b){
DBManager db = new DBManager();
List<TeacherCourse> list = new ArrayList<TeacherCourse>();
String sql ="select Teacher.Stno,Stname,Course.Cno,Cname,Clno "+
"from Course,TC,Teacher "+
"where Teacher.Stno=TC.Stno and TC.Cno=Course.Cno and Teacher.Stno='"+name+"'and Course.Cno='"+b+"'" ;
System.out.println(sql);
ResultSet rs = db.executeQuery(sql);
try {
while (rs.next()){
TeacherCourse user = new TeacherCourse();
user.setStno(rs.getString("Stno").trim());
System.out.println(user.getStno());
user.setStname(rs.getString("Stname").trim());
System.out.println(user.getStname());
user.setCno(rs.getString("Cno"));
System.out.println(user.getCno());
user.setCname(rs.getString("Cname"));
System.out.println(user.getCname());
user.setClno(rs.getString("Clno"));
list.add(user);
}
}
catch (SQLException e) {
System.out.println("失败");
}
db.Close();
return list;
}
public List<StudentCourse> Studentcourse( ){
DBManager db = new DBManager();
List<StudentCourse> list = new ArrayList<StudentCourse>();
String sql ="select Student.sno,sum(Scg)as Allgrade from Student,Sc where Student.Sno=Sc.Sno group by Student.sno";
System.out.println(sql);
ResultSet rs = db.executeQuery(sql);
try {
while (rs.next()){
StudentCourse user = new StudentCourse();
user.setSno(rs.getString("Sno").trim());
System.out.println(user.getSno());
user.setCgrade(rs.getInt("Allgrade"));
list.add(user);
}
}
catch (SQLException e) {
System.out.println("失败");
}
db.Close();
return list;
}
public List<TeacherCourse> IndexTeacherSelectCourse1(String name){
DBManager db = new DBManager();
List<TeacherCourse> list = new ArrayList<TeacherCourse>();
String sql ="select Teacher.Stno,Stname,Course.Cno,Cname,Clno "+
"from Course,TC,Teacher "+
"where Teacher.Stno=TC.Stno and TC.Cno=Course.Cno and Teacher.Stno='"+name+"'" ;
System.out.println(sql);
ResultSet rs = db.executeQuery(sql);
try {
while (rs.next()){
TeacherCourse user = new TeacherCourse();
user.setStno(rs.getString("Stno").trim());
System.out.println(user.getStno());
user.setStname(rs.getString("Stname").trim());
System.out.println(user.getStname());
user.setCno(rs.getString("Cno"));
System.out.println(user.getCno());
user.setCname(rs.getString("Cname"));
System.out.println(user.getCname());
user.setClno(rs.getString("Clno"));
list.add(user);
}
}
catch (SQLException e) {
System.out.println("失败");
}
db.Close();
return list;
}
public List<TeacherCourse> IndexTeacherSelectCourse(String name){
DBManager db = new DBManager();
List<TeacherCourse> list = new ArrayList<TeacherCourse>();
String sql ="select Teacher.Stno,Stname,Course.Cno,Cname,Clno "+
"from Course,TC,Teacher,Userperson "+
"where Userperson.SID=Teacher.Stno and Teacher.Stno=TC.Stno and TC.Cno=Course.Cno "
+"and Susername='"+name+"'";
System.out.println(sql);
ResultSet rs = db.executeQuery(sql);
try {
while (rs.next()){
TeacherCourse user = new TeacherCourse();
user.setStno(rs.getString("Stno").trim());
System.out.println(user.getStno());
user.setStname(rs.getString("Stname").trim());
System.out.println(user.getStname());
user.setCno(rs.getString("Cno"));
System.out.println(user.getCno());
user.setCname(rs.getString("Cname"));
System.out.println(user.getCname());
user.setClno(rs.getString("Clno"));
list.add(user);
}
}
catch (SQLException e) {
System.out.println("失败");
}
db.Close();
return list;
}
public List<TeacherCourse> Teacher_SelectCourse(){
DBManager db = new DBManager();
List<TeacherCourse> list = new ArrayList<TeacherCourse>();
String sql ="select Teacher.Stno,Stname,Course.Cno,Cname,Clno "+
"from Course,TC,Teacher,Userperson "+
"where Userperson.SID=Teacher.Stno and Teacher.Stno=TC.Stno and TC.Cno=Course.Cno ";
System.out.println(sql);
ResultSet rs = db.executeQuery(sql);
try {
while (rs.next()){
TeacherCourse user = new TeacherCourse();
user.setStno(rs.getString("Stno").trim());
System.out.println(user.getStno());
user.setStname(rs.getString("Stname").trim());
System.out.println(user.getStname());
user.setCno(rs.getString("Cno"));
System.out.println(user.getCno());
user.setCname(rs.getString("Cname"));
System.out.println(user.getCname());
user.setClno(rs.getString("Clno"));
list.add(user);
}
}
catch (SQLException e) {
System.out.println("失败");
}
db.Close();
return list;
}
public List<StudentCourse> StudentcourseSelect(String name){
DBManager db = new DBManager();
List<StudentCourse> list = new ArrayList<StudentCourse>();
String sql ="select Student.sno,sum(Scg)as Allgrade from Student,Sc where Student.sno='"+name+"'and Student.Sno=Sc.Sno group by Student.sno";
System.out.println(sql);
ResultSet rs = db.executeQuery(sql);
try {
while (rs.next()){
StudentCourse user = new StudentCourse();
user.setSno(rs.getString("Sno").trim());
System.out.println(user.getSno());
user.setCgrade(rs.getInt("Allgrade"));
list.add(user);
}
}
catch (SQLException e) {
System.out.println("失败");
}
db.Close();
return list;
}
public List<Course> StudentSelectCourse(){
DBManager db = new DBManager();
List<Course> list = new ArrayList<Course>();
String sql ="select * from Course";
System.out.println(sql);
ResultSet rs = db.executeQuery(sql);
try {
while (rs.next()){
Course user = new Course();
user.setCno(rs.getString("Cno").trim());
System.out.println(user.getCno());
user.setCname(rs.getString("Cname").trim());
System.out.println(user.getCname());
user.setCgrade(rs.getInt("Cgrade"));
user.setCtime(rs.getInt("Ctime"));
System.out.println(user.getCname());
user.setType(rs.getString("Ctype"));
list.add(user);
}
}
catch (SQLException e) {
System.out.println("失败");
}
db.Close();
return list;
}
public List<Teacher> TeacherInformation(){
DBManager db = new DBManager();
List<Teacher> list = new ArrayList<Teacher>();
String sql ="select * from Teacher";
System.out.println(sql);
ResultSet rs = db.executeQuery(sql);
try {
while (rs.next()){
Teacher user = new Teacher();
user.setStno(rs.getString("Stno").trim());
System.out.println(user.getStno());
user.setStname(rs.getString("Stname").trim());
System.out.println(user.getStname());
user.setStsex(rs.getString("Stsex"));
System.out.println(user.getStsex());
user.setStage(rs.getInt("Stage"));
System.out.println(user.getStage());
user.setSto(rs.getString("Sto"));
list.add(user);
}
}
catch (SQLException e) {
System.out.println("失败");
}
db.Close();
return list;
}
public List<Teacher> index_teacher_user(String name){
DBManager db = new DBManager();
List<Teacher> list = new ArrayList<Teacher>();
String sql ="select Teacher.Stno,Stname,Stsex,Stage,Sto from Userperson,Teacher where Userperson.SID=Teacher.Stno and Susername='"+name+"'";
System.out.println(sql);
ResultSet rs = db.executeQuery(sql);
try {
while (rs.next()){
Teacher user = new Teacher();
user.setStno(rs.getString("Stno").trim());
System.out.println(user.getStno());
user.setStname(rs.getString("Stname").trim());
System.out.println(user.getStname());
user.setStsex(rs.getString("Stsex"));
System.out.println(user.getStsex());
user.setStage(rs.getInt("Stage"));
System.out.println(user.getStage());
user.setSto(rs.getString("Sto"));
list.add(user);
}
}
catch (SQLException e) {
System.out.println("失败");
}
db.Close();
return list;
}
public List<Teacher> index_teacher_user2(String name){
DBManager db = new DBManager();
List<Teacher> list = new ArrayList<Teacher>();
String sql ="select * from Teacher where Stno='"+name+"'";
System.out.println(sql);
ResultSet rs = db.executeQuery(sql);
try {
while (rs.next()){
Teacher user = new Teacher();
user.setStno(rs.getString("Stno").trim());
System.out.println(user.getStno());
user.setStname(rs.getString("Stname").trim());
System.out.println(user.getStname());
user.setStsex(rs.getString("Stsex"));
System.out.println(user.getStsex());
user.setStage(rs.getInt("Stage"));
System.out.println(user.getStage());
user.setSto(rs.getString("Sto"));
list.add(user);
}
}
catch (SQLException e) {
System.out.println("失败");
}
db.Close();
return list;
}
public List<Student> index_teacher_StudentInformation(){
DBManager db = new DBManager();
List<Student> list = new ArrayList<Student>();
String sql ="select * from Student";
System.out.println(sql);
ResultSet rs = db.executeQuery(sql);
try {
while (rs.next()){
Student user = new Student();
user.setSno(rs.getString("Sno").trim());
System.out.println(user.getSno());
user.setSname(rs.getString("Sname").trim());
System.out.println(user.getSname());
user.setSsex(rs.getString("Ssex"));
System.out.println(user.getSsex());
user.setSage(rs.getInt("Sage"));
System.out.println(user.getSage());
user.setSdept(rs.getString("Sdept"));
user.setClno(rs.getString("Clno"));
list.add(user);
}
}
catch (SQLException e) {
System.out.println("失败");
}
db.Close();
return list;
}
public List<Course> Course(String name){
DBManager db = new DBManager();
List<Course> list = new ArrayList<Course>();
String sql ="select * from Course where Cno='"+name+"'";
System.out.println(sql);
ResultSet rs = db.executeQuery(sql);
try {
while (rs.next()){
Course user = new Course();
user.setCno(rs.getString("Cno").trim());
System.out.println(user.getCno());
user.setCname(rs.getString("Cname").trim());
System.out.println(user.getCname());
user.setCgrade(rs.getInt("Cgrade"));
user.setCtime(rs.getInt("Ctime"));
System.out.println(user.getCname());
user.setType(rs.getString("Ctype"));
list.add(user);
}
}
catch (SQLException e) {
System.out.println("失败");
}
db.Close();
return list;
}
public void delete(String id) {
DBManager db = new DBManager();
String sql = "delete from Student where Sno='"+id+"'";
System.out.println(sql);
db.executeUpdate(sql);
}
public void deleteAll(String string,String x){
DBManager db = new DBManager();
String sql = "delete from SC where Sno='"+string+"' and Cno='"+x+"'";
System.out.println(sql);
db.executeUpdate(sql);
}
public void deleteAn(String string){
DBManager db = new DBManager();
String sql = "delete from SC where Sno='"+string+"'";
System.out.println(sql);
db.executeUpdate(sql);
}
public void deleteTeacherInformation(String string){
DBManager db = new DBManager();
String sql = "delete from Teacher where Stno='"+string+"'";
System.out.println(sql);
db.executeUpdate(sql);
}
public void deleteTeacherCoures(String string){
DBManager db = new DBManager();
String sql = "delete from Course where Cno='"+string+"'";
System.out.println(sql);
db.executeUpdate(sql);
}
public void deleteSelectCourse(String string,String Cno){
DBManager db = new DBManager();
String sql = "delete from TC where Stno='"+string+"' and Cno='"+Cno+"'";
System.out.println(sql);
db.executeUpdate(sql);
}
public String insertTeacherManager(String Stno,String Stname,String Stsex,String Ssage,String Sto){
String message=null;
DBManager db=new DBManager();
String sql="insert into Teacher(Stno,Stname,Stsex,Stage,Sto) values('"+Stno+"','"+Stname+"','"+Stsex+"','"+Ssage+"','"+Sto+"')";
System.out.println(sql);
int d=db.executeUpdate(sql);
if(d==0){
message="插入失败,请检查数据是否正确";}
return message;
}
public String updateStudentInformation(String Sno,String Sname,String Ssex,String Sage,String Sdept,String Clno){
String message=null;
DBManager db=new DBManager();
String sql="update Student set Sname='"+Sname+"', Ssex='"+Ssex+"', Sage='"+Sage+"', Sdept='"+Sdept+"', Clno='"+Clno+"' where Sno='"+Sno+"'";
System.out.println(sql);
int d=db.executeUpdate(sql);
if(d==0){
message="修改失败,请检查数据是否正确";}
return message;
}
public String updateTeacher(String Stno,String Stname,String Stsex,String Stage,String Sto){
String message=null;
DBManager db=new DBManager();
String sql="update Teacher set Stname='"+Stname+"', Stsex='"+Stsex+"', Stage='"+Stage+"', Sto='"+Sto+"' where Stno='"+Stno+"'";
System.out.println(sql);
int d=db.executeUpdate(sql);
if(d==0){
message="修改失败,请检查数据是否正确";}
return message;
}
@Override
public void resetInfo(String username,String password,String mpass) {
DBManager db = new DBManager();
String sql = "update Userperson set Spassword='"+mpass+"' where Susername='"+username+"'and Spassword='"+password+"'";
System.out.println(sql);
db.executeUpdate(sql);
db.Close1();
}
public String updateCourse(String Cno,String Cname,String Cgrade,String Ctime,String Ctype){
DBManager db = new DBManager();
String sql = "update Course set Cname='"+Cname+"', Cgrade='"+Cgrade+"', Ctime='"+Ctime+"', Ctype='"+Ctype+"' where Cno='"+Cno+"'";
System.out.println(sql);
int d=db.executeUpdate(sql);
String message=null;
if(d==0){
message="修改失败,请检查数据是否正确";}
return message;
}
public String updateSelect(String Stno,String OCno,String Cno,String Clo){
DBManager db = new DBManager();
String sql = "update TC set Cno='"+Cno+"', Clno='"+Clo+"' where Cno='"+OCno+"' and Stno='"+Stno+"'";
System.out.println(sql);
int d=db.executeUpdate(sql);
String message=null;
if(d==0){
message="修改失败,请检查数据是否正确";}
return message;
}
public void updateGradeAll(String Sno,String Cno,String Sname,String Cname,String Scg){
DBManager db = new DBManager();
String sql = "update Student set Sname='"+Sname+"'where Sno='"+Sno+"'";
String sql2="update Course set Cname='"+Cname+"'where Cno='"+Cno+"'";
String sql3="update SC set Scg='"+Scg+"' where Sno='"+Sno+"' and Cno='"+Cno+"'";
System.out.println(sql);System.out.println(sql2);System.out.println(sql3);
db.executeUpdate(sql);
db.executeUpdate(sql2);
db.executeUpdate(sql3);
}
public String AddStudentInformation(String Sno,String Sname,String Ssex,String Sage,String Sdept,String Clno){
String message=null;
DBManager db=new DBManager();
String sql="insert into Student(Sno,Sname,Ssex,Sage,Sdept,Clno) values('"+Sno+"','"+Sname+"','"+Ssex+"','"+Sage+"','"+Sdept+"','"+Clno+"')";
System.out.println(sql);
int d=db.executeUpdate(sql);
if(d==0){
message="插入失败,请检查数据是否正确";}
return message;
}
public String AddCourse(String Cno,String Cname,String Cgrade,String Ctime,String Ctype){
String message=null;
DBManager db=new DBManager();
String sql="insert into Course(Cno,Cname,Cgrade,Ctime,Ctype) values('"+Cno+"','"+Cname+"','"+Cgrade+"','"+Ctime+"','"+Ctype+"')";
System.out.println(sql);
int d=db.executeUpdate(sql);
if(d==0){
message="插入失败,请检查数据是否正确";}
return message;
}
public String AddSelect(String Stno,String Cno,String Clno){
String message=null;
DBManager db=new DBManager();
String sql="insert into TC(Stno,Cno,Clno) values('"+Stno+"','"+Cno+"','"+Clno+"')";
System.out.println(sql);
int d=db.executeUpdate(sql);
if(d==0){
message="插入失败,请检查数据是否正确";}
return message;
}
public void AddGradeAll(String Sno,String Cno,String Sname,String Cname,String Scg){
DBManager db = new DBManager();
String sql="insert into Student(Sno,Sname)values('"+Sno+"','"+Sname+"')";
String sql2="insert into Course(Cno,Cname)values('"+Cno+"','"+Cname+"')";
String sql3="insert into SC(Sno,Cno,Scg)values('"+Sno+"','"+Cno+"','"+Scg+"')";
System.out.println(sql);System.out.println(sql2);System.out.println(sql3);
db.executeUpdate(sql);
db.executeUpdate(sql2);
db.executeUpdate(sql3);
}
}
6.登录界面login.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 lang="zh-cn">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<meta name="renderer" content="webkit">
<title>登录</title>
<link rel="stylesheet" href="css/pintuer.css">
<link rel="stylesheet" href="css/admin.css">
<script src="js/jquery.js"></script>
<script src="js/pintuer.js"></script>
<script type="text/javascript">
function refresh() {
//IE存在缓存,需要new Date()实现更换路径的作用
document.getElementById("image").src="image.jsp?"+new Date();
}
</script>
</head>
<body>
<% String message = (String)session.getAttribute("message");%>
<%if(message!=null){
if(message.equals("验证码出错")){
%>
<script type="text/javascript">
alert("请输入正确的验证码");
</script>
<% }%>
<%if(message.equals("用户名或密码输入错误")){
%>
<script type="text/javascript">
alert("用户名或密码输入错误");
</script>
<%}%>
<%message=null;
session.setAttribute("message",message);%>
<%}%>
<div class="bg"></div>
<div class="container">
<div class="line bouncein">
<div class="xs6 xm4 xs3-move xm4-move">
<div style="height:150px;"></div>
<div class="media media-y margin-big-bottom">
</div>
<form action="first" method="post">
<input type="hidden" name="jsp" value="login">
<div class="panel loginbox">
<div class="text-center margin-big padding-big-top"><h1>学生成绩管理系统</h1></div>
<div class="panel-body" style="padding:30px; padding-bottom:10px; padding-top:10px;">
<div class="form-group">
<div class="field field-icon-right">
<input type="text" class="input input-big" name="name" placeholder="登录账号" data-validate="required:请填写账号" />
<span class="icon icon-user margin-small"></span>
</div>
</div>
<div class="form-group">
<div class="field field-icon-right">
<input type="password" class="input input-big" name="password" placeholder="登录密码" data-validate="required:请填写密码" />
<span class="icon icon-key margin-small"></span>
</div>
</div>
<hr>
<div class="form-group">
<div class="field person">
用户类型:
<input type="radio" name="usertype" value="student" />学生
<input type="radio" name="usertype" value="teacher" />教师
<input type="radio" name="usertype" value="manager" />管理员
</div>
</div>
<br>
验证码:<input type="text" name="code" maxlength="4">
<img id="image" border="0" onclick="refresh()" src="image.jsp" title="点击更换图片">
</div>
<div style="padding:30px;"><input type="submit" class="button button-block bg-main text-big input-big" value="登录"></div>
</div>
</form>
</div>
</div>
</div>
</body>
</html>
7.验证码:images.jsp
<%@page import="javax.imageio.ImageIO"%>
<%@page import="java.awt.Font"%>
<%@page import="java.awt.Graphics"%>
<%@page import="java.awt.image.BufferedImage"%>
<%@page import="java.util.Random"%>
<%@page import="java.awt.Color"%>
<%@ page language="java" contentType="image/JPEG; charset=UTF-8"
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);
}
%>
<%
//设置页面不缓存
response.setHeader("Pragma", "No-cache");
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", 0);
//在内存中创建图像
int width = 60;
int 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 < 100; 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);
}
//随机产生4位验证码
String[] codes = {
"2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H","J","K","L","M","N","P","Q","R","S","T","U","V","W","X","Y","Z"};
String code = "";
for(int i=0;i<4;i++){
String str = codes[random.nextInt(codes.length)];
code += str;
// 将认证码显示到图象中
g.setColor(new Color(20 + random.nextInt(110), 20 + random.nextInt(110), 20 + random.nextInt(110)));
//调用函数出来的颜色相同,可能是因为种子太接近,所以只能直接生成
g.drawString(str, 13 * i + 6, 16);
}
// 将认证码存入SESSION
session.setAttribute("code", code);
// 图象生效
g.dispose();
// 输出图象到页面
ImageIO.write(image, "JPEG", response.getOutputStream());
//加上下面代码,运行时才不会出现java.lang.IllegalStateException: getOutputStream() has already been called ..........等异常
response.getOutputStream().flush();
response.getOutputStream().close();
response.flushBuffer();
out.clear();
out = pageContext.pushBody();
%>
8.学生登录后主页面index.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@page import="java.util.ArrayList"%>
<%@page import="com.dqpi.Model.User" %>
<%@page import="java.util.List"%>
<!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" href="../css/pintuer.css">
<link rel="stylesheet" href="../css/admin.css">
<script src="../js/jquery.js"></script>
</head>
<body style="background-color:#f2f9fd;">
<div class="header bg-main">
<div class="logo margin-big-left fadein-top">
<h1><img src="../images/y.jpg" class="radius-circle rotate-hover" height="50" alt="" />学生成绩管理系统</h1>
</div>
<div class="head-l">
<a class="button button-little bg-red" href="../login.jsp" >
<span class="icon-power-off"></span> 退出登录</a> </div>
</div>
<div class="leftnav">
<div class="leftnav-title"><strong><span class="icon-list"></span>菜单列表</strong></div>
<h2><span class="icon-user"></span>用户信息</h2>
<ul>
<li><a href="../common/personal_details.jsp" target="right">账户信息</a></li>
<li><a href="../common/personnew.jsp" target="right"><span class="icon-caret-right"></span>修改密码</a></li>
</ul>
<h2><span class="icon-pencil-square-o"></span>学生信息</h2>
<ul >
<li><a href="first?Ajsp=main.index" target="right" ><span class="icon-caret-right"></span>查询学生信息</a></li>
</ul>
<h2><span class="icon-pencil-square-o"></span>课程信息</h2>
<ul >
<li><a href="first?Ajsp=main.index.select" target="right"><span class="icon-caret-right"></span>查询课程信息</a></li>
</ul>
<h2><span class="icon-pencil-square-o"></span>成绩信息</h2>
<ul>
<li><a href="first?Ajsp=main.index.course&type=grade" target="right"><span class="icon-caret-right"></span>查询成绩</a></li>
</ul>
<h2><span class="icon-pencil-square-o"></span>选课信息</h2>
<ul>
<li><a href="first?Ajsp=main.index.course&type=course" target="right"><span class="icon-caret-right"></span>查看选课</a></li>
</ul>
</div>
<script type="text/javascript">
$(function(){
$(".leftnav h2").click(function(){
$(this).next().slideToggle(200);
$(this).toggleClass("on");
})
$(".leftnav ul li a").click(function(){
$("#a_leader_txt").text($(this).text());
$(".leftnav ul li a").removeClass("on");
$(this).addClass("on");
})
$(".icon-home").click(function(){
$("#a_leader_txt").text("所有公告");
$(".leftnav ul li a").removeClass("on");
$(this).addClass("on");
})
});
</script>
<ul class="bread">
<li><a href="welcome.jsp" target="right" class="icon-home"> 首页</a></li>
<li><a href="" id="a_leader_txt">公告信息</a></li>
</ul>
<div class="admin">
<iframe scrolling="auto" rameborder="0" src="welcome.jsp" name="right" width="100%" height="100%"></iframe>
</div>
<div style="text-align:center;">
</div>
</body>
</html>
9.教师登录后主页面index(teacher).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" href="../css/pintuer.css">
<link rel="stylesheet" href="../css/admin.css">
<script src="../js/jquery.js"></script>
</head>
<body style="background-color:#f2f9fd;">
<div class="header bg-main">
<div class="logo margin-big-left fadein-top">
<h1><img src="../images/y.jpg" class="radius-circle rotate-hover" height="50" alt="" />学生成绩管理系统</h1>
</div>
<div class="head-l">
<a class="button button-little bg-red" href="../login.jsp" >
<span class="icon-power-off"></span> 退出登录</a> </div>
</div>
<div class="leftnav">
<div class="leftnav-title"><strong><span class="icon-list"></span>菜单列表</strong></div>
<h2><span class="icon-user"></span>用户信息</h2>
<ul>
<li><a href="../common/personal_details.jsp" target="right"><span class="icon-caret-right"></span>账户信息</a></li>
<li><a href="../common/personnew.jsp" target="right"><span class="icon-caret-right"></span>修改密码</a></li>
</ul>
<h2><span class="icon-user"></span>学生信息</h2>
<ul>
<li><a href="first?Ajsp=index(teacher).StudentInformation" target="right"><span class="icon-caret-right"></span>查看学生信息</a></li>
</ul>
<h2><span class="icon-pencil-square-o"></span>用户信息</h2>
<ul >
<li><a href="first?Ajsp=index(teacher).user" target="right"><span class="icon-caret-right"></span>查询用户</a></li>
</ul>
<h2><span class="icon-pencil-square-o"></span>课程信息</h2>
<ul >
<li><a href="first?Ajsp=main.index.select" target="right"><span class="icon-caret-right"></span>查询课程信息</a></li>
</ul>
<h2><span class="icon-pencil-square-o"></span>成绩管理</h2>
<ul>
<li><a href="first?Ajsp=index(teacher).Student.Grade" target="right"><span class="icon-caret-right"></span>成绩管理</a></li>
</ul>
<h2><span class="icon-pencil-square-o"></span>选课管理</h2>
<ul>
<li><a href="first?Ajsp=index(teacher).selectCourse" target="right"><span class="icon-caret-right"></span>查看选课</a></li>
</ul>
</div>
<script type="text/javascript">
$(function(){
$(".leftnav h2").click(function(){
$(this).next().slideToggle(200);
$(this).toggleClass("on");
})
$(".leftnav ul li a").click(function(){
$("#a_leader_txt").text($(this).text());
$(".leftnav ul li a").removeClass("on");
$(this).addClass("on");
})
$(".icon-home").click(function(){
$("#a_leader_txt").text("所有公告");
$(".leftnav ul li a").removeClass("on");
$(this).addClass("on");
})
});
</script>
<ul class="bread">
<li><a href="welcome.jsp" target="right" class="icon-home"> 首页</a></li>
<li><a href="" id="a_leader_txt">公告信息</a></li>
</ul>
<div class="admin">
<iframe scrolling="auto" rameborder="0" src="welcome.jsp" name="right" width="100%" height="100%"></iframe>
</div>
<div style="text-align:center;">
</div>
</body>
</html>