Javaweb
后端:Java1.8
前端:html+js+css
数据库:MySQL8.0+navicat17
jsp:jstl c标签 ajax
服务器:servlet
项目采用mvc三层架构:业务逻辑层、服务层、持久层
实现前端界面与数据库信息交互
数据库:
身份1为老师,0为学生
项目结构:
bean:
package cm.stu.bean; public class Person { //`userAccount``userName``usersex``userBirthday``userIdCard``userPassword``userIdentify``userOtherName` private String userAccount; private String userName; private String userSex; private String userBirthday; private String userIdCard; private String userPassword; private int userIdentify; private String userOtherName; public Person() { } public Person(String userAccount, String userName, String userSex, String userBirthday, String userIdCard, String userPassword, int userIdentify, String userOtherName) { this.userAccount = userAccount; this.userName = userName; this.userSex = userSex; this.userBirthday = userBirthday; this.userIdCard = userIdCard; this.userPassword = userPassword; this.userIdentify = userIdentify; this.userOtherName = userOtherName; } public Person(String userAccount, String userPassword) { this.userAccount = userAccount; this.userPassword = userPassword; } public String getUserAccount() { return userAccount; } public void setUserAccount(String userAccount) { this.userAccount = userAccount; } public String getUserName() { return userName; } public void setUserName(String userName) { this.userName = userName; } public String getUserSex() { return userSex; } public void setUserSex(String userSex) { this.userSex = userSex; } public String getUserBirthday() { return userBirthday; } public void setUserBirthday(String userBirthday) { this.userBirthday = userBirthday; } public String getUserIdCard() { return userIdCard; } public void setUserIdCard(String userIdCard) { this.userIdCard = userIdCard; } public String getUserPassword() { return userPassword; } public void setUserPassword(String userPassword) { this.userPassword = userPassword; } public int getUserIdentify() { return userIdentify; } public void setUserIdentify(int userIdentify) { this.userIdentify = userIdentify; } public String getUserOtherName() { return userOtherName; } public void setUserOtherName(String userOtherName) { this.userOtherName = userOtherName; } @Override public String toString() { return "Person{" + "userAccount='" + userAccount + '\'' + ", userName='" + userName + '\'' + ", userSex='" + userSex + '\'' + ", userBirthday='" + userBirthday + '\'' + ", userIdCard='" + userIdCard + '\'' + ", userPassword='" + userPassword + '\'' + ", userIdentify=" + userIdentify + ", userOtherName='" + userOtherName + '\'' + '}'; } }
package cm.stu.bean; public class StudentAnswer { //`taskAccount``studentAccount``studentAnswer``isFinish``isScore``userName``taskName` private String taskAccount; private String studentAccount; private String studentAnswer; private int isFinish; private int isScore; private String userName; private String taskName; public String getTaskAccount() { return taskAccount; } public void setTaskAccount(String taskAccount) { this.taskAccount = taskAccount; } public String getStudentAccount() { return studentAccount; } public void setStudentAccount(String studentAccount) { this.studentAccount = studentAccount; } public String getStudentAnswer() { return studentAnswer; } public void setStudentAnswer(String studentAnswer) { this.studentAnswer = studentAnswer; } public int getIsFinish() { return isFinish; } public void setIsFinish(int isFinish) { this.isFinish = isFinish; } public int getIsScore() { return isScore; } public void setIsScore(int isScore) { this.isScore = isScore; } public String getUserName() { return userName; } public void setUserName(String userName) { this.userName = userName; } public String getTaskName() { return taskName; } public void setTaskName(String taskName) { this.taskName = taskName; } }
package cm.stu.bean; public class Task { //`taskAccount``teacherAccount``taskDate``taskName` private String taskAccount; private String teacherAccount; private String taskDate; private String taskName; public Task() { } public Task(String taskAccount, String teacherAccount, String taskDate, String taskName) { this.taskAccount = taskAccount; this.teacherAccount = teacherAccount; this.taskDate = taskDate; this.taskName = taskName; } public String getTaskAccount() { return taskAccount; } public void setTaskAccount(String taskAccount) { this.taskAccount = taskAccount; } public String getTeacherAccount() { return teacherAccount; } public void setTeacherAccount(String teacherAccount) { this.teacherAccount = teacherAccount; } public String getTaskDate() { return taskDate; } public void setTaskDate(String taskDate) { this.taskDate = taskDate; } public String getTaskName() { return taskName; } public void setTaskName(String taskName) { this.taskName = taskName; } @Override public String toString() { return "Task{" + "taskAccount='" + taskAccount + '\'' + ", teacherAccount='" + teacherAccount + '\'' + ", taskDate='" + taskDate + '\'' + ", taskName='" + taskName + '\'' + '}'; } }
dao:
package cm.stu.dao; import cm.stu.bean.Person; import cm.stu.bean.StudentAnswer; import cm.stu.bean.Task; import cm.stu.util.ConnectionFactory; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.List; public class Deal { public static List<Person> getAllPerson(String sql) { Connection connection = ConnectionFactory.getConnection(); PreparedStatement pre = null; ResultSet res = null; List<Person> list = new ArrayList<>(); try { pre =connection.prepareStatement(sql); res = pre.executeQuery(); while(res.next()){ Person newPerson = new Person(); //`userAccount``userName``usersex``userBirthday``userIdCard``userPassword``userIdentify``userOtherName` newPerson.setUserAccount(res.getString("userAccount")); newPerson.setUserName(res.getString("userName")); newPerson.setUserSex(res.getString("userSex")); newPerson.setUserBirthday(res.getString("userBirthday")); newPerson.setUserIdCard(res.getString("userIdCard")); newPerson.setUserPassword(res.getString("userPassword")); newPerson.setUserIdentify(res.getInt("userIdentify")); newPerson.setUserOtherName(res.getString("userOtherName")); list.add(newPerson); } } catch (SQLException throwables) { throwables.printStackTrace(); }finally { } return list; } public static List<Task> getAllMyTask(String sql) { Connection connection = ConnectionFactory.getConnection(); PreparedStatement pre = null; ResultSet res = null; List<Task> list = new ArrayList<>(); try { pre =connection.prepareStatement(sql); res = pre.executeQuery(); while(res.next()){ Task task = new Task(); //`taskAccount``teacherAccount``taskDate``taskName` task.setTaskAccount(res.getString("taskAccount")); task.setTaskDate(res.getString("taskDate")); task.setTaskName(res.getString("taskName")); task.setTeacherAccount(res.getString("teacherAccount")); list.add(task); } } catch (SQLException throwables) { throwables.printStackTrace(); }finally { } return list; } public static List<StudentAnswer> getTaskDetail(String sql) { Connection connection = ConnectionFactory.getConnection(); PreparedStatement pre = null; ResultSet res = null; List<StudentAnswer> list = new ArrayList<>(); try { pre =connection.prepareStatement(sql); res = pre.executeQuery(); while(res.next()){ StudentAnswer sa = new StudentAnswer(); `taskAccount``studentAccount``studentAnswer``isFinish``isScore``userName``taskName` sa.setTaskAccount(res.getString("taskAccount")); sa.setStudentAccount(res.getString("studentAccount")); sa.setStudentAnswer(res.getString("studentAnswer")); sa.setIsFinish(res.getInt("isFinish")); sa.setIsScore(res.getInt("isScore")); sa.setUserName(res.getString("userName")); sa.setTaskName(res.getString("taskName")); list.add(sa); } } catch (SQLException throwables) { throwables.printStackTrace(); }finally { } return list; } public static int isExist(String sql) { Connection connection = ConnectionFactory.getConnection(); PreparedStatement pre = null; ResultSet res = null; int num=0; try { pre =connection.prepareStatement(sql); res = pre.executeQuery(); while(res.next()){ num = res.getInt("num"); } } catch (SQLException throwables) { throwables.printStackTrace(); }finally { } return num; } public static void deal(String sql) { Connection connection = ConnectionFactory.getConnection(); PreparedStatement pre = null; ResultSet res = null; try { pre =connection.prepareStatement(sql); pre.execute(); } catch (SQLException throwables) { throwables.printStackTrace(); }finally { } } }
package cm.stu.dao; public class Generate { public static int isExistTaskAccount(String taskAccount) { String sql = "select count(*) num from task where taskAccount='"+taskAccount+"'"; return Deal.isExist(sql); } public static int IsExistStuTea(String userAccount, String teacherAccount) { //`userteacher` `userAccount``teacherAccount` String sql = "select count(*) num from userteacher where userAccount='"+userAccount+"' and teacherAccount='"+teacherAccount+"'"; return Deal.isExist(sql); } public static int isExistPersonAccount(String userAccount) { String sql = "select count(*) num from person where userAccount='"+userAccount+"'"; return Deal.isExist(sql); } }
package cm.stu.dao; import cm.stu.bean.Person; import java.util.List; public interface ManageDao { List<Person> getAllPerson(); List<Person> getSearch(String matchText); void addPerson(Person newPerson); void sureUpPassword(String userAccount, String userPassword); void delThisPerson(String delAccount, String userIdentify); }
package cm.stu.dao; import cm.stu.bean.Person; import cm.stu.util.ConnectionFactory; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.List; public class ManageDaoImpl implements ManageDao { @Override public List<Person> getAllPerson() { String sql = "select * from person where userIdentify!=2"; return Deal.getAllPerson(sql); } @Override public List<Person> getSearch(String matchText) { String sql = "select * from person where userIdentify!=2 and (userAccount='' or userName like '%"+matchText+"%' or userIdCard='"+matchText+"')"; return Deal.getAllPerson(sql); } @Override public void addPerson(Person newPerson) { String sql = "insert into person values('"+newPerson.getUserAccount()+"','"+newPerson.getUserName()+"','"+newPerson.getUserSex()+"','"+newPerson.getUserBirthday()+"','"+newPerson.getUserIdCard()+"','"+newPerson.getUserPassword()+"',"+newPerson.getUserIdentify()+",'"+newPerson.getUserOtherName()+"')"; Deal.deal(sql); } @Override public void sureUpPassword(String userAccount, String userPassword) { String sql = "update person set userPassword = '"+userPassword+"' where userAccount='"+userAccount+"'"; Deal.deal(sql); } @Override public void delThisPerson(String delAccount, String userIdentify) { if(Integer.parseInt(userIdentify)==0){ //删除学生 String sql = "DELETE FROM userteacher WHERE `userAccount` = '"+delAccount+"'"; Deal.deal(sql); sql = "DELETE FROM studenttask WHERE studentAccount = '"+delAccount+"'"; Deal.deal(sql); }else{ //删除老师 String sql = "DELETE FROM `studenttask` WHERE taskAccount IN (SELECT taskAccount FROM task WHERE teacherAccount='"+delAccount+"')"; Deal.deal(sql); sql = "DELETE FROM task WHERE teacherAccount = '"+delAccount+"'"; Deal.deal(sql); sql = "DELETE FROM userteacher WHERE teacherAccount = '"+delAccount+"'"; Deal.deal(sql); } String sql = "DELETE FROM person WHERE userAccount = '"+delAccount+"'"; Deal.deal(sql); } }
package cm.stu.dao; import cm.stu.bean.Person; import cm.stu.bean.StudentAnswer; import java.util.List; public interface StudentDao { List<Person> getAllTeacher(); List<Person> getSearchTeacher(String matchText); List<Person> getMyTeacher(String userAccount); void addTeacher(String userAccount, String teacherAccount); List<StudentAnswer> goMyTeaTask(String userAccount, String teacherAccount); void deleteMyTeacher(String userAccount, String teacherAccount); void doAnswer(String userAccount, String taskAccount, String answer); void dealFenshu(String taskAccount, String studentAccount, String fenshu); }
package cm.stu.dao; import cm.stu.bean.Person; import cm.stu.bean.StudentAnswer; import java.util.List; public class StudentDaoImpl implements StudentDao { @Override public List<Person> getAllTeacher() { String sql = "select * from person where userIdentify=1"; return Deal.getAllPerson(sql); } @Override public List<Person> getSearchTeacher(String matchText) { String sql = "SELECT * FROM person WHERE userIdentify=1 AND (userAccount='"+matchText+"' OR userName LIKE'%"+matchText+"%' OR userOtherName LIKE'%"+matchText+"%')"; return Deal.getAllPerson(sql); } @Override public List<Person> getMyTeacher(String userAccount) { String sql = "SELECT * FROM person WHERE userAccount IN (SELECT `teacherAccount` AS userAccount FROM userteacher ut WHERE ut.`userAccount`='"+userAccount+"')"; return Deal.getAllPerson(sql); } @Override public void addTeacher(String userAccount, String teacherAccount) { //`userteacher` `userAccount``teacherAccount` String sql = "insert into userteacher values('"+userAccount+"','"+teacherAccount+"')"; Deal.deal(sql); } @Override public List<StudentAnswer> goMyTeaTask(String userAccount, String teacherAccount) { String sql = "SELECT s.*,p.`userName`,`taskName` FROM `studenttask` s INNER JOIN person p ON s.`studentAccount`=p.`userAccount` INNER JOIN task t ON s.`taskAccount`=t.taskAccount WHERE (s.`studentAccount`='"+userAccount+"' AND t.`teacherAccount`='"+teacherAccount+"')"; return Deal.getTaskDetail(sql); } @Override public void deleteMyTeacher(String userAccount, String teacherAccount) { String sql = "DELETE FROM `userteacher` WHERE `userAccount`='"+userAccount+"' AND `teacherAccount`='"+teacherAccount+"'"; Deal.deal(sql); sql = "DELETE FROM `studenttask` WHERE `taskAccount` IN(SELECT `taskAccount` FROM `task` WHERE `teacherAccount`='"+teacherAccount+"') AND studentAccount='"+userAccount+"'"; Deal.deal(sql); } @Override public void doAnswer(String userAccount, String taskAccount, String answer) { String sql = "UPDATE studenttask SET `studentAnswer`='"+answer+"',`isFinish`=1 WHERE `taskAccount`='"+taskAccount+"' AND `studentAccount`='"+userAccount+"'"; Deal.deal(sql); } @Override public void dealFenshu(String taskAccount, String studentAccount, String fenshu) { String sql = "UPDATE studenttask SET `isScore`='"+fenshu+"',`isFinish`=2 WHERE `taskAccount`='"+taskAccount+"' AND `studentAccount`='"+studentAccount+"'"; Deal.deal(sql); } }
package cm.stu.dao; import cm.stu.bean.StudentAnswer; import cm.stu.bean.Task; import java.util.List; public interface TeacherDao { List AllStudentsByTeacherAccount(String userAccount); List<Task> getAllMyTask(String userAccount); List<StudentAnswer> getTaskDetail(String taskAccount); void AddTask(Task task); List getSearchStudentByTeacherAccount(String userAccount,String matchText); List<StudentAnswer> goStudentTaskDetail(String userAccount, String studentAccount); void deleteTask(String taskAccount,String studentAccount, String isFinish); void deleteThisTask(String taskAccount); void deleteThisPersonByTeacher(String studentAccount, String userAccount); }
package cm.stu.dao; import cm.stu.bean.StudentAnswer; import cm.stu.bean.Task; import java.util.List; public class TeacherDaoImpl implements TeacherDao { @Override public List AllStudentsByTeacherAccount(String userAccount) { String sql = "SELECT * FROM `person` WHERE userAccount IN(SELECT userAccount FROM `userteacher` WHERE teacherAccount='"+userAccount+"')"; return Deal.getAllPerson(sql); } @Override public List<Task> getAllMyTask(String userAccount) { String sql = "SELECT * FROM task WHERE teacherAccount = '"+userAccount+"'"; return Deal.getAllMyTask(sql); } @Override public List<StudentAnswer> getTaskDetail(String taskAccount) { String sql ="SELECT s.*,p.`userName`,`taskName` FROM `studenttask` s INNER JOIN person p ON s.`studentAccount`=p.`userAccount` INNER JOIN task t ON s.`taskAccount`=t.taskAccount WHERE s.`taskAccount`='"+taskAccount+"'"; return Deal.getTaskDetail(sql); } @Override public void AddTask(Task task) { //`taskAccount``teacherAccount``taskDate``taskName` String sql = "INSERT INTO task VALUES('"+task.getTaskAccount()+"','"+task.getTeacherAccount()+"','"+task.getTaskDate()+"','"+task.getTaskName()+"')"; Deal.deal(sql); sql= "INSERT INTO `studenttask`(`taskAccount`,`studentAccount`,`studentAnswer`,`isFinish`,`isScore`) SELECT '"+task.getTaskAccount()+"',B.C,NULL,0,0 FROM (SELECT `userAccount` C FROM `userteacher` WHERE `teacherAccount`='"+task.getTeacherAccount()+"') AS B"; Deal.deal(sql); } @Override public List getSearchStudentByTeacherAccount(String userAccount,String matchText) { String sql = "SELECT * FROM person WHERE userAccount IN (SELECT `userAccount` FROM `userteacher` WHERE `teacherAccount`='"+userAccount+"') AND (`userAccount`='"+matchText+"' OR `userName` LIKE'%"+matchText+"%' OR `userIdCard` ='"+matchText+"')"; return Deal.getAllPerson(sql); } @Override public List<StudentAnswer> goStudentTaskDetail(String userAccount, String studentAccount) { String sql ="SELECT s.*,p.`userName`,`taskName` FROM `studenttask` s INNER JOIN person p ON " + "s.`studentAccount`=p.`userAccount` INNER JOIN task t ON s.`taskAccount`=t.taskAccount WHERE (s.`studentAccount`='"+studentAccount+"' AND t.`teacherAccount`='"+userAccount+"')"; return Deal.getTaskDetail(sql); } @Override public void deleteTask(String taskAccount,String studentAccount, String isFinish) { if(Integer.parseInt(isFinish)==0){ //直接删除 String sql = "DELETE FROM studenttask WHERE taskAccount ='"+taskAccount+"' AND studentAccount = '"+studentAccount+"'"; Deal.deal(sql); }else{ // } } @Override public void deleteThisTask(String taskAccount) { String sql = "DELETE FROM task WHERE taskAccount='"+taskAccount+"'"; Deal.deal(sql); sql = "DELETE FROM studenttask WHERE taskAccount='"+taskAccount+"'"; Deal.deal(sql); } @Override public void deleteThisPersonByTeacher(String studentAccount, String userAccount) { String sql = "DELETE FROM `userteacher` WHERE `userAccount`='"+studentAccount+"' AND `teacherAccount`='"+userAccount+"'"; Deal.deal(sql); sql = "DELETE FROM `studenttask` WHERE `taskAccount` IN(SELECT `taskAccount` FROM `task` WHERE `teacherAccount`='"+userAccount+"') AND studentAccount='"+studentAccount+"'"; Deal.deal(sql); } }
package cm.stu.dao; import cm.stu.bean.Person; public interface UserLoginDao { Person getLogin(Person person); }
package cm.stu.dao; import cm.stu.bean.Person; import cm.stu.util.ConnectionFactory; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; public class UserLoginDaoImpl implements UserLoginDao { @Override public Person getLogin(Person person) { String sql = "select * from person where userAccount='"+person.getUserAccount()+"' and userPassword='"+person.getUserPassword()+"'"; Connection connection = ConnectionFactory.getConnection(); PreparedStatement pre = null; ResultSet res = null; Person newPerson = null; try { pre =connection.prepareStatement(sql); res = pre.executeQuery(); while(res.next()){ newPerson = new Person(); //`userAccount``userName``usersex``userBirthday``userIdCard``userPassword``userIdentify``userOtherName` newPerson.setUserAccount(res.getString("userAccount")); newPerson.setUserName(res.getString("userName")); newPerson.setUserSex(res.getString("userSex")); newPerson.setUserBirthday(res.getString("userBirthday")); newPerson.setUserIdCard(res.getString("userIdCard")); newPerson.setUserPassword(res.getString("userPassword")); newPerson.setUserIdentify(res.getInt("userIdentify")); newPerson.setUserOtherName(res.getString("userOtherName")); } } catch (SQLException throwables) { throwables.printStackTrace(); }finally { } return newPerson; } }
service:
package cm.stu.service; import cm.stu.bean.Person; import java.util.List; public interface ManageService { List<Person> getAllPerson(); List<Person> getSearch(String matchText); void addPerson(Person newPerson); void sureUpPassword(String userAccount, String userPassword); void delThisPerson(String delAccount, String userIdentify); }
package cm.stu.service; import cm.stu.bean.Person; import cm.stu.dao.ManageDao; import cm.stu.dao.ManageDaoImpl; import java.util.List; public class ManageServiceImpl implements ManageService { ManageDao md = new ManageDaoImpl(); @Override public List<Person> getAllPerson() { return md.getAllPerson(); } @Override public List<Person> getSearch(String matchText) { return md.getSearch(matchText); } @Override public void addPerson(Person newPerson) { md.addPerson(newPerson); } @Override public void sureUpPassword(String userAccount, String userPassword) { md.sureUpPassword(userAccount,userPassword); } @Override public void delThisPerson(String delAccount, String userIdentify) { md.delThisPerson(delAccount,userIdentify); } }
package cm.stu.service; import cm.stu.bean.Person; import cm.stu.bean.StudentAnswer; import java.util.List; public interface StudentService { List<Person> getAllTeacher(); List<Person> getSearchTeacher(String matchText); List<Person> getMyTeacher(String userAccount); void addTeacher(String userAccount, String teacherAccount); List<StudentAnswer> goMyTeaTask(String userAccount, String teacherAccount); void deleteMyTeacher(String userAccount, String teacherAccount); void doAnswer(String userAccount, String taskAccount, String answer); void dealFenshu(String taskAccount, String studentAccount, String fenshu); }
package cm.stu.service; import cm.stu.bean.Person; import cm.stu.bean.StudentAnswer; import cm.stu.dao.Deal; import cm.stu.dao.StudentDao; import cm.stu.dao.StudentDaoImpl; import java.util.List; public class StudentServiceImpl implements StudentService { StudentDao sd = new StudentDaoImpl(); @Override public List<Person> getAllTeacher() { return sd.getAllTeacher(); } @Override public List<Person> getSearchTeacher(String matchText) { return sd.getSearchTeacher(matchText); } @Override public List<Person> getMyTeacher(String userAccount) { return sd.getMyTeacher(userAccount); } @Override public void addTeacher(String userAccount, String teacherAccount) { sd.addTeacher(userAccount,teacherAccount); } @Override public List<StudentAnswer> goMyTeaTask(String userAccount, String teacherAccount) { return sd.goMyTeaTask(userAccount,teacherAccount); } @Override public void deleteMyTeacher(String userAccount, String teacherAccount) { sd.deleteMyTeacher(userAccount,teacherAccount); } @Override public void doAnswer(String userAccount, String taskAccount, String answer) { sd.doAnswer(userAccount,taskAccount,answer); } @Override public void dealFenshu(String taskAccount, String studentAccount, String fenshu) { sd.dealFenshu(taskAccount,studentAccount,fenshu); } }
package cm.stu.service; import cm.stu.bean.StudentAnswer; import cm.stu.bean.Task; import java.util.List; public interface TeacherService { List AllStudentsByTeacherAccount(String userAccount); List<Task> getAllMyTask(String userAccount); List<StudentAnswer> getTaskDetail(String taskAccount); void AddTask(Task task); List getSearchStudentByTeacherAccount(String userAccount,String matchText); List<StudentAnswer> goStudentTaskDetail(String userAccount, String studentAccount); void deleteTask(String taskAccount,String studentAccount, String isFinish); void deleteThisTask(String taskAccount); void deleteThisPersonByTeacher(String studentAccount, String userAccount); }
package cm.stu.service; import cm.stu.bean.StudentAnswer; import cm.stu.bean.Task; import cm.stu.dao.TeacherDao; import cm.stu.dao.TeacherDaoImpl; import java.util.List; public class TeacherServiceImpl implements TeacherService { TeacherDao td = new TeacherDaoImpl(); @Override public List AllStudentsByTeacherAccount(String userAccount) { return td.AllStudentsByTeacherAccount(userAccount); } @Override public List<Task> getAllMyTask(String userAccount) { return td.getAllMyTask(userAccount); } @Override public List<StudentAnswer> getTaskDetail(String taskAccount) { return td.getTaskDetail(taskAccount); } @Override public void AddTask(Task task) { td.AddTask(task); } @Override public List getSearchStudentByTeacherAccount(String userAccount,String matchText) { return td.getSearchStudentByTeacherAccount(userAccount,matchText); } @Override public List<StudentAnswer> goStudentTaskDetail(String userAccount, String studentAccount) { return td.goStudentTaskDetail(userAccount,studentAccount); } @Override public void deleteTask(String taskAccount,String studentAccount, String isFinish) { td.deleteTask(taskAccount,studentAccount,isFinish); } @Override public void deleteThisTask(String taskAccount) { td.deleteThisTask(taskAccount); } @Override public void deleteThisPersonByTeacher(String studentAccount, String userAccount) { td.deleteThisPersonByTeacher(studentAccount,userAccount); } }
package cm.stu.service; import cm.stu.bean.Person; public interface UserLoginService { Person getLogin(Person person); }
package cm.stu.service; import cm.stu.bean.Person; import cm.stu.dao.UserLoginDao; import cm.stu.dao.UserLoginDaoImpl; public class UserLoginServiceImpl implements UserLoginService { UserLoginDao ud = new UserLoginDaoImpl(); @Override public Person getLogin(Person person) { return ud.getLogin(person); } }
servlet:
package cm.stu.servlet; import cm.stu.bean.Person; import cm.stu.service.ManageService; import cm.stu.service.ManageServiceImpl; import cm.stu.service.StudentService; import cm.stu.service.StudentServiceImpl; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; @WebServlet("/common.action") public class CommonServlet extends HttpServlet { @Override protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { req.setCharacterEncoding("UTF-8"); String action = req.getParameter("action"); StudentService ss = new StudentServiceImpl(); Person person = (Person) req.getSession().getAttribute("session_person"); String userAccount = person.getUserAccount(); ManageService ms = new ManageServiceImpl(); if(action.equals("index")){ //跳转到首页 req.setAttribute("mainRight","blank.jsp"); req.getRequestDispatcher("main.jsp").forward(req,resp); }else if(action.equals("goMyDetail")){ req.setAttribute("mainRight","detail.jsp"); req.getRequestDispatcher("main.jsp").forward(req,resp); }else if(action.equals("upPassword")){ //upPassword req.getRequestDispatcher("upPassword.jsp").forward(req,resp); }else if(action.equals("sureUpPassword")){ //common.action?action=sureUpPassword String userPassword = req.getParameter("userPassword"); ms.sureUpPassword(userAccount,userPassword); req.setAttribute("tip","修改成功,请关闭此页面"); req.getRequestDispatcher("success.jsp").forward(req,resp); } } }
package cm.stu.servlet; import cm.stu.bean.Person; import cm.stu.service.ManageService; import cm.stu.service.ManageServiceImpl; import cm.stu.util.Test; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.util.List; @WebServlet("/man.action") public class ManageServlet extends HttpServlet { @Override protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { req.setCharacterEncoding("UTF-8"); String action = req.getParameter("action"); ManageService ms = new ManageServiceImpl(); if (action.equals("list") || action.equals("search")||action.equals("delThisPerson")) { //man.action?action=delThisPerson&userAccount="+userAccount+"&userIdentify="+userIdentify List<Person> arr; if (action.equals("list")||action.equals("delThisPerson")) { if(action.equals("delThisPerson")){ String delAccount = req.getParameter("userAccount"); String userIdentify = req.getParameter("userIdentify"); ms.delThisPerson(delAccount,userIdentify); } arr = ms.getAllPerson(); } else { String matchText = (req.getParameter("matchText")).trim(); arr = ms.getSearch(matchText); } req.setAttribute("arr", arr); req.setAttribute("mainRight", "person.jsp"); req.getRequestDispatcher("main.jsp").forward(req, resp); } else if (action.equals("goAddPerson")) { req.setAttribute("mainRight", "addPerson.jsp"); req.getRequestDispatcher("main.jsp").forward(req, resp); } else if (action.equals("addThisPerson")) { String newUserAccount = Test.getPersonAccount(); String userName = req.getParameter("userName"); String userSex = req.getParameter("userSex"); String userBirthday = req.getParameter("userBirthday"); String userIdCard = req.getParameter("userIdCard"); String userPassword = req.getParameter("userPassword"); int userIdentify = Integer.parseInt(req.getParameter("userIdentify")); String userOtherName = req.getParameter("userOtherName"); Person newPerson = new Person(newUserAccount, userName, userSex, userBirthday, userIdCard, userPassword, userIdentify, userOtherName); ms.addPerson(newPerson); req.setAttribute("tip","添加完成"); req.setAttribute("mainRight", "blank.jsp"); req.getRequestDispatcher("main.jsp").forward(req, resp); } } }
package cm.stu.servlet; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import java.io.IOException; @WebServlet("/outLogin") public class OutLoginServlet extends HttpServlet { @Override protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { HttpSession session = req.getSession(); session.removeAttribute("session_person"); req.getRequestDispatcher("userLogin.jsp").forward(req,resp); } }
package cm.stu.servlet; import cm.stu.bean.Person; import cm.stu.bean.StudentAnswer; import cm.stu.dao.Generate; import cm.stu.service.StudentService; import cm.stu.service.StudentServiceImpl; import cm.stu.service.TeacherService; import cm.stu.service.TeacherServiceImpl; import cm.stu.util.Test; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.util.List; @WebServlet("/student.action") public class StudentServlet extends HttpServlet { @Override protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { req.setCharacterEncoding("UTF-8"); String action = req.getParameter("action"); StudentService ss = new StudentServiceImpl(); Person person = (Person) req.getSession().getAttribute("session_person"); String userAccount = person.getUserAccount(); //"student.action?action=searchTeacher" if(action.equals("list")||action.equals("searchTeacher")){ List<Person> arr ; if(action.equals("list")){ arr = ss.getAllTeacher(); }else { String matchText = req.getParameter("matchText"); arr = ss.getSearchTeacher(matchText); } req.setAttribute("arr",arr); req.setAttribute("mainRight","person.jsp"); req.getRequestDispatcher("main.jsp").forward(req,resp); }else if(action.equals("goMyTeacher")||action.equals("deleteMyTeacher")){ //student.action?action=goMyTeacher //student.action?action=deleteMyTeacher&teacherAccount="+teacherAccount; if(action.equals("deleteMyTeacher")){ String teacherAccount = req.getParameter("teacherAccount"); ss.deleteMyTeacher(userAccount,teacherAccount); } List<Person> arr = ss.getMyTeacher(userAccount); req.setAttribute("arr",arr); req.setAttribute("mainRight","myTeacher.jsp"); req.getRequestDispatcher("main.jsp").forward(req,resp); }else if(action.equals("addTeacher")){ //addTeacher&teacherAccount=" String teacherAccount = req.getParameter("teacherAccount"); int flag = Generate.IsExistStuTea(userAccount,teacherAccount); if(flag==0){ ss.addTeacher(userAccount,teacherAccount); req.setAttribute("tip","添加成功"); }else { req.setAttribute("tip","你已经选择这个老师,本次选择失败!"); } req.setAttribute("mainRight","blank.jsp"); req.getRequestDispatcher("main.jsp").forward(req,resp); }else if(action.equals("goMyTeaTask")){ // "student.action?action=goMyTeaTask&teacherAccount="+teacherAccount String teacherAccount = req.getParameter("teacherAccount"); List<StudentAnswer> arr = ss.goMyTeaTask(userAccount,teacherAccount); req.setAttribute("arr",arr); req.setAttribute("mainRight","studentTask.jsp"); req.getRequestDispatcher("main.jsp").forward(req,resp); }else if(action.equals("doAnswer")){ // stu.action?action=doAnswer&taskAccount="+taskAccount+"", String taskAccount = req.getParameter("taskAccount"); req.setAttribute("taskAccount",taskAccount); req.getRequestDispatcher("doAnswer.jsp").forward(req,resp); }else if(action.equals("dealAnswer")){ //"student.action?action=doAnswer&taskAccount="+taskAccount String taskAccount = req.getParameter("taskAccount"); String answer = (req.getParameter("answer")).trim(); System.out.println(taskAccount+" "+answer); ss.doAnswer(userAccount,taskAccount,answer); req.setAttribute("tip","恭喜答题完成,请关闭页面等待老师的更改!"); req.getRequestDispatcher("success.jsp").forward(req,resp); }else if(action.equals("doFenshu")){ //student.action?action=doFenshu&taskAccount="+taskAccount+"&studentAccount="+studentAccount, String taskAccount = req.getParameter("taskAccount"); String studentAccount = req.getParameter("studentAccount"); req.setAttribute("taskAccount",taskAccount); req.setAttribute("studentAccount",studentAccount); req.getRequestDispatcher("getFenshu.jsp").forward(req,resp); }else if(action.equals("getFenshu")){ //action="student.action?action=getFenshu&taskAccount=${taskAccount}&studentAccount=${studentAccount}" String taskAccount = req.getParameter("taskAccount"); String studentAccount = req.getParameter("studentAccount"); String fenshu = req.getParameter("fenshu"); ss.dealFenshu(taskAccount,studentAccount,fenshu); req.setAttribute("tip","已修改分数!"); req.getRequestDispatcher("success.jsp").forward(req,resp); } } }
package cm.stu.servlet; import cm.stu.bean.Person; import cm.stu.bean.StudentAnswer; import cm.stu.bean.Task; import cm.stu.service.TeacherService; import cm.stu.service.TeacherServiceImpl; import cm.stu.util.Test; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.util.List; @WebServlet("/tea.action") public class TeacherServlet extends HttpServlet { @Override protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { req.setCharacterEncoding("UTF-8"); String action = req.getParameter("action"); TeacherService ts = new TeacherServiceImpl(); Person person = (Person) req.getSession().getAttribute("session_person"); String userAccount = person.getUserAccount(); //<li id="file"><a href="tea.action?action=list">学生管理</a></li> if(action.equals("list")||action.equals("searchMyStudent")||action.equals("deleteThisPersonByTeacher")){ //"tea.action?action=deleteThisPersonByTeacher&studentAccount"+studentAccount List arr = null; //searchMyStudent matchText- if(action.equals("searchMyStudent")){ String matchText = req.getParameter("matchText"); arr = ts.getSearchStudentByTeacherAccount(userAccount,matchText); }else { if(action.equals("deleteThisPersonByTeacher")){ String studentAccount = req.getParameter("studentAccount"); ts.deleteThisPersonByTeacher(studentAccount,userAccount); } arr = ts.AllStudentsByTeacherAccount(userAccount); } //获取所有学生的信息 req.setAttribute("arr",arr); req.setAttribute("mainRight","person.jsp"); req.getRequestDispatcher("main.jsp").forward(req,resp); }else if(action.equals("goMyTask")||action.equals("deleteTishTask")){ //"tea.action?action=deleteTishTask&taskAccount="+taskAccount; if(action.equals("deleteTishTask")){ String taskAccount = req.getParameter("taskAccount"); ts.deleteThisTask(taskAccount); } List<Task> arr = ts.getAllMyTask(userAccount); req.setAttribute("arr",arr); req.setAttribute("mainRight","task.jsp"); req.getRequestDispatcher("main.jsp").forward(req,resp); }else if(action.equals("goSkimDetail")||action.equals("goStudentTaskDetail")){ List<StudentAnswer> arr; //"tea.action?action=deleteTask&studentAccount=" + studentAccount + "&isFinish=" + isFinish if(action.equals("goSkimDetail")){ String taskAccount = req.getParameter("taskAccount"); arr = ts.getTaskDetail(taskAccount); }else { req.setAttribute("sign","goStudentTaskDetail"); String studentAccount = req.getParameter("studentAccount"); arr = ts.goStudentTaskDetail(userAccount,studentAccount); } //tea.action?action=goSkimDetail&taskAccount="+taskAccount; req.setAttribute("arr",arr); req.setAttribute("mainRight","studentTask.jsp"); req.getRequestDispatcher("main.jsp").forward(req,resp); }else if(action.equals("deleteTask")){ // "&isFinish=" + isFinish String studentAccount = req.getParameter("studentAccount"); String taskAccount = req.getParameter("taskAccount"); String isFinish = req.getParameter("isFinish"); ts.deleteTask(taskAccount,studentAccount,isFinish); req.setAttribute("tip","删除成功"); req.setAttribute("mainRight","blank.jsp"); req.getRequestDispatcher("main.jsp").forward(req,resp); }else if(action.equals("goAddTask")||action.equals("addTask")){ if(action.equals("addTask")){ String taskName = req.getParameter("taskName"); taskName = taskName.trim(); if(taskName.equals("")){ req.setAttribute("tip","添加失败"); }else{ //朝着数据库存入 String date = Test.getDate(); String taskAccount =Test.getTaskAccount(); Task task = new Task(taskAccount,userAccount,date,taskName); ts.AddTask(task); req.setAttribute("tip","添加成功"); } } req.setAttribute("mainRight","addTask.jsp"); req.getRequestDispatcher("main.jsp").forward(req,resp); }else if(action.equals("addPerson")){ req.setAttribute("mainRight","addPerson.jsp"); req.getRequestDispatcher("main.jsp").forward(req,resp); } } }
package cm.stu.servlet; import cm.stu.bean.Person; import cm.stu.service.UserLoginService; import cm.stu.service.UserLoginServiceImpl; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import java.io.IOException; @WebServlet("/userLogin") public class UserLoginServlet extends HttpServlet { @Override protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { req.setCharacterEncoding("UTF-8"); //首先去拿到前端传过来的信息 String userAccount = req.getParameter("userAccount"); String userPassword = req.getParameter("userPassword"); Person person = new Person(userAccount,userPassword); UserLoginService ul = new UserLoginServiceImpl(); Person newPerson = ul.getLogin(person); if(newPerson!=null){ // req.getSession().setAttribute("session-person",newPerson); HttpSession session = req.getSession(); session.setAttribute("session_person",newPerson); req.setAttribute("mainRight","blank.jsp"); req.getRequestDispatcher("main.jsp").forward(req,resp); }else{ //继续回到登陆注册界面 req.setAttribute("tip","账户密码不一致"); req.getRequestDispatcher("userLogin.jsp").forward(req,resp); } } }
util:
package cm.stu.util; import com.mchange.v2.c3p0.ComboPooledDataSource; import javax.sql.DataSource; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; public class ConnectionFactory { //获取数据源 自动读取c3p0-config.xml文件 private static DataSource dataSource = new ComboPooledDataSource(); //获取连接 public static Connection getConnection() { try { return dataSource.getConnection(); } catch (SQLException e) { e.printStackTrace(); } return null; } //资源关闭工具方法 public static void close(Connection connection,PreparedStatement preparedStatement,ResultSet resultSet) { try { //释放资源,根据先开后放 if(resultSet != null) resultSet.close(); if(preparedStatement != null) preparedStatement.close(); if(connection != null) connection.close(); } catch (SQLException e) { e.printStackTrace(); } } }
package cm.stu.util; import cm.stu.bean.Person; import cm.stu.dao.Deal; import cm.stu.dao.Generate; import java.text.SimpleDateFormat; import java.util.Date; public class Test { public static void main(String[] args) { Deal.deal("INSERT INTO task VALUES('11','11','11','11')"); } public static String getDate() { Date date = new Date(System.currentTimeMillis()); SimpleDateFormat sdt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); return sdt.format(date); } public static String getTaskAccount() { String taskAccount =""; while (true){ for(int i=0;i<8;i++){ taskAccount = taskAccount+Integer.toString((int)(1+Math.random()*(10-1+1))); } int num = Generate.isExistTaskAccount(taskAccount); if(num==0){ break; }else { taskAccount=""; } } return taskAccount; } public static String getPersonAccount() { String userAccount =""; while (true){ for(int i=0;i<8;i++){ userAccount = userAccount+Integer.toString((int)(1+Math.random()*(10-1+1))); } int num = Generate.isExistPersonAccount(userAccount); if(num==0){ break; }else { userAccount=""; } } return userAccount; } }
连接数据库:
c3p0-config.xml
<?xml version="1.0" encoding="UTF-8"?> <c3p0-config> <default-config> <property name="driverClass">com.mysql.cj.jdbc.Driver</property> <!-- 注意端口号和表名称--> <property name="jdbcUrl">jdbc:mysql://localhost:3306/astu?useSSL=false&serverTimezone=Asia/Shanghai&characterEncoding=utf-8&autoReconnect=true</property> <property name="user">root</property> <property name="password">123456</property>//使用自己数据库的密码 <property name="acquireIncrement">10</property> <property name="initialPoolSize">10</property> <property name="maxPoolSize">100</property> <property name="maxIdleTime">60</property> <property name="minPoolSize">5</property> </default-config> </c3p0-config>
前端()
Web
css:
table{ width: 1200px; } tr,td{ border: grey 1px ; } td{ height: 40px; } table td{ height: 60px; vertical-align: middle!important; /*设置文字垂直居中*/ text-align: center; } tr,td{border-right:1px solid #888;border-bottom:1px solid #888;padding:5px 15px;} th{font-weight:bold;background:#ccc;} .con-b .row .lf{ width: 15%; text-align: center; padding: 10px; } .con-b .row .rg{ width: 85%; } .con-b tr:nth-of-type(odd){ background-color: #f2f2f2; }
lib:
需要用到的jar包私信我!!!
一系列jsp:
登陆界面userLogin.jsp:
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>登录界面</title> <style> #outerLoginFrame{ width: 500px; height: 400px; margin-left: 600px; margin-top: 260px; } #innerLoginFrame{ width: 360px; margin-left: 100px; margin-top: 45px; color: grey; font-size: 25px; } input{ width: 220px; height: 30px; } </style> </head> <body> <div id="outerLoginFrame" style="border: grey 2px solid"> <%-- <span style="position: center"></span>--%> <h1 style="margin-top: 40px;margin-left: 130px;">教 务 管 理 系 统</h1> <div id="innerLoginFrame" style="font-size: 30px"> <form action="userLogin" method="post" οnsubmit="return checkLogin()"> 账户:<input type="text" style="font-size: 28px" id="userAccount" name="userAccount" class="myText"><br><br> 密码:<input type="password" style="font-size: 28px" id="userPassword" name="userPassword" class="myText"><br><br> <input style="width: 140px;margin-left: 20px" type="submit" value="登录"> <%-- <a href="register.jsp" style="width: 140px;margin-left: 20px"> | 注册</a><br>--%> <span style="color: red;font-size: 15px" id="tip">${tip}</span> </form> </div> </div> </body> </html> <script> function checkLogin() { let userAccount = document.getElementById("userAccount").value; let userPassword = document.getElementById("userPassword").value; if(userAccount==null||userAccount.trim()==""){ document.getElementById("tip").innerHTML = "账户不能为空"; return false; } if(userPassword==null||userPassword.trim()==""){ document.getElementById("tip").innerHTML = "密码不能为空"; return false; } return true; } </script>
主界面main.jsp:
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>Title</title> <style> #BigBodyFrame{ width: 1600px; height: 120px; border: grey 2px solid; background-image: url("head.png"); } #daohang{ width: 250px; /*height: 100%;*/ float: left; border: grey 1px solid; } #file{ width: 230px; height: 50px; margin-left: 11px; margin-top: 10px; border: grey 1px solid; background-color: mediumslateblue; } a{ color: white; font-size: 26px; margin-left: 30px; margin-top: 25px; } </style> <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <link href="${pageContext.request.contextPath}/css/css.css" rel="stylesheet" media="screen"> </head> <body> <div id="BigBodyFrame"></div> <br> <span style="float: right;color: grey;margin-right: 120px"> 当前用户:${session_person.userName}</span><br> <c:if test="${session_person.userName=='李四'}">hahha</c:if> <br> <div id="daohang"> <c:if test="${session_person.userIdentify == 0}"> <li id="file"><a href="common.action?action=index">查看首页</a></li> <li id="file"><a href="student.action?action=list">选择老师</a></li> <li id="file"><a href="student.action?action=goMyTeacher">我的老师</a></li> <li id="file"><a href="common.action?action=goMyDetail">我的信息</a></li> <li id="file"><a href="outLogin">退出系统</a></li> </c:if> <c:if test="${session_person.userIdentify == 1}"> <li id="file"><a href="common.action?action=index">查看首页</a></li> <li id="file"><a href="tea.action?action=list">学生管理</a></li> <li id="file"><a href="tea.action?action=goMyTask">任务管理</a></li> <li id="file"><a href="tea.action?action=goAddTask">添加任务</a></li> <li id="file"><a href="common.action?action=goMyDetail">我的信息</a></li> <li id="file"><a href="outLogin">退出系统</a></li> </c:if> <c:if test="${session_person.userIdentify == 2}"> <li id="file"><a href="common.action?action=index">查看首页</a></li> <li id="file"><a href="man.action?action=list">人员管理</a></li> <li id="file"><a href="man.action?action=goAddPerson">人员添加</a></li> <li id="file"><a href="common.action?action=goMyDetail">我的信息</a></li> <li id="file"><a href="outLogin">退出系统</a></li> </c:if> <%-- <div id="file" οnclick="clickThis()"></div>--%> </div> <jsp:include page="${mainRignt=null?'blank.jsp':mainRight}"></jsp:include> </body> </html>
主界面旁边的提示信息blank.jsp:
<head> <title>Title</title> <style> #content{ width: 1300px; height: 800px; float: right; margin-right: 40px; color: grey; font-size: 50px; } </style> </head> <body> <div id="content"> 欢迎来到此系统<br> <span style="font-size: 10px;color: red">${tip}</span> </div> </body> </html>
用户person.jsp:
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>Title</title> <style> table{ width: 1300px; } tr,td{ border: grey 1px ; } td{ height: 40px; } table td{ height: 60px; vertical-align: middle!important; /*设置文字垂直居中*/ text-align: center; } tr,td{border-right:1px solid #888;border-bottom:1px solid #888;padding:5px 15px;} th{font-weight:bold;background:#ccc;} .con-b .row .lf{ width: 15%; text-align: center; padding: 10px; } .con-b .row .rg{ width: 85%; } .con-b tr:nth-of-type(odd){ background-color: #f2f2f2; } #content{ width: 1300px; height: 70px; float: right; border: grey 1px solid; margin-right: 40px; color: grey; font-size: 50px; } </style> <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> </head> <body> <%--<div style=" width:1300px;height:100px;margin-lef:450px;background-color: aliceblue;border: red 1px solid"></div>--%> <div id="content"> <%-- searchMyStudent matchText--%> <div style="float: right;height: 70px"> <c:if test="${session_person.getUserIdentify()==0}"> <form action="student.action?action=searchTeacher" method="post"> </c:if> <c:if test="${session_person.getUserIdentify()==1}"> <form action="tea.action?action=searchMyStudent" method="post"> </c:if> <c:if test="${session_person.getUserIdentify()==2}"> <form action="man.action?action=search" method="post"> </c:if> <input type="text" name="matchText" style="height: 35px;width: 500px;font-size: 28px;color: darkslateblue;border: grey solid 1px;"> <input type="submit" style="margin-left: 6px;margin-right: 30px" value="查询"> </form> </div> </div> <br><br> <table border="1" cellspacing="0" align="center" class="con-b"> <thead> <%-- `userAccount``userName``userSex``userBirthday``userIdCard``userIdentify``userOtherName`--%> <tr class="row" style="color: black;font-size: 25px" > <td class="lf">账户</td> <td class="lf">姓名</td> <td class="lf" style="width: 10%">性别</td> <c:if test="${session_person.getUserIdentify()!=0}"> <td class="lf">生日</td> <td class="lf">身份证号码</td> <td class="lf">角色</td> </c:if> <td class="lf">其他名称</td> <c:if test="${session_person.getUserIdentify()!=0}"> <td>删除</td> </c:if> <c:if test="${session_person.getUserIdentify()!=2}"> <td style="width: 10%">操作</td> </c:if> </tr> </thead> <tbody> <c:forEach items="${arr}" var="person"> <tr> <td class="lf">${person.getUserAccount()}</td> <td class="lf">${person.getUserName()}</td> <td class="lf">${person.getUserSex()}</td> <c:if test="${session_person.getUserIdentify()!=0}"> <td class="lf">${person.getUserBirthday()}</td> <td class="lf">${person.getUserIdCard()}</td> <td class="lf"> <c:if test="${person.getUserIdentify()==0}"> 学生 </c:if> <c:if test="${person.getUserIdentify()==1}"> 老师 </c:if> </td> </c:if> <td class="lf">${person.getUserOtherName()}</td> <c:if test="${session_person.getUserIdentify()==1}"> <td> <img src="del.png" οnclick="deleteThisPersonByTeacher('${person.getUserAccount()}')"> </td> </c:if> <c:if test="${session_person.getUserIdentify()==2}"> <td> <img src="del.png" οnclick="delThisPerson('${person.getUserAccount()}','${person.getUserIdentify()}')"> </td> </c:if> <c:if test="${session_person.getUserIdentify()!=0}"> <td> <c:if test="${session_person.getUserIdentify()==1}"> <img style="width: 40px;height: 40px" src="detail.jpg" οnclick="detailTask('${person.getUserAccount()}')"> <%-- <img src="detail.jpg" οnclick="detailTask('${person.getUserAccount()}')">--%> </c:if> </td> </c:if> <c:if test="${session_person.getUserIdentify()==0}"> <td><img style="width:40px;height: 40px" οnclick="addTeacher('${person.getUserAccount()}')" src="addTeacher.png"></td> </c:if> </tr> </c:forEach> </tbody> </table> </body> <script> function delThisPerson(userAccount,userIdentify) { window.location.href = "man.action?action=delThisPerson&userAccount="+userAccount+"&userIdentify="+userIdentify } function addTeacher(teacherAccount) { window.location.href = "student.action?action=addTeacher&teacherAccount="+teacherAccount } function detailTask(studentAccount) { window.location.href = "tea.action?action=goStudentTaskDetail&studentAccount="+studentAccount; } function deleteThisPersonByTeacher(studentAccount) { alert(studentAccount) window.location.href = "tea.action?action=deleteThisPersonByTeacher&studentAccount="+studentAccount } function upThisPerson(userAccount) { alert("修改:"+userAccount) } </script> </html>
添加用户addPerson.jsp:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %> <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <script type="text/javascript"> </script> <div class="data_list"> </div> <form method="post" action="man.action?action=addThisPerson" οnsubmit="return checkThis()"> <div class="data_form"> <table align="center"> <tr> <td><font color="red">*</font>姓名:</td> <td><input type="text" id="userName" name="userName" style="margin-top:5px;height:30px;"/></td> </tr> <tr> <td><font color="red">*</font>性别:</td> <td> <input type="radio" name="userSex" value="男" checked="checked"> 男 <input type="radio" name="userSex" value="女">女<br> </tr> <tr> <td><font color="red">*</font>出生日期:</td> <td><input type="date" id="userBirthday" name="userBirthday" style="margin-top:5px;height:30px;"/></td> </tr> <tr> <td><font color="red">*</font>身份证号码:</td> <td><input type="text" id="userIdCard" name="userIdCard" style="margin-top:5px;height:30px;"/> </td> </tr> <tr> <td><font color="red">*</font>手机号码:</td> <td><input type="number" id="userPhone" name="userPhone" style="margin-top:5px;height:30px;"/> </td> </tr> <tr> <td><font color="red">*</font>角色:</td> <td> <select id="userIdentify" name="userIdentify" style="width: 205px" ;> <%-- 绝密、机密、秘密、非秘级--%> <option id="a" value="0">学生</option> <option id="b" value="1">老师</option> </select> </td> </tr> <tr> <td><font color="red">*</font>职务:</td> <td><input type="text" id="nikeName" name="userOtherName" placeholder="某科老师/学生" style="margin-top:5px;height:30px;"/></td> </tr> <tr> <td><font color="red">*</font>输入密码:</td> <td><input type="password" id="userPassword" name="userPassword" style="margin-top:5px;height:30px;"/></td> </tr> <tr> <td><font color="red">*</font>再次密码:</td> <td><input type="password" id="rUserPassword" name="rUserPassword" style="margin-top:5px;height:30px;"/></td> </tr> <script> function checkThis() { let userName = document.getElementById("userName").value; let userIdCard = document.getElementById("userIdCard").value; let nikeName = document.getElementById("nikeName").value; let userPassword = document.getElementById("userPassword").value; let userPhone = document.getElementById("userPhone").value; let rUserPassword = document.getElementById("rUserPassword").value; if (userName.trim() == null || userName.trim() == "") { document.getElementById("error").innerHTML = "姓名不能为空"; return false; } if (userIdCard.trim() == null || userIdCard.trim() == "") { document.getElementById("error").innerHTML = "身份证号码不能为空"; return false; } if (userPhone.trim() == null || userPhone.trim() == "") { document.getElementById("error").innerHTML = "手机号码不能为空"; return false; } if (nikeName.trim() == null || nikeName.trim() == "") { document.getElementById("error").innerHTML = "职称不能为空"; return false; } if (userPassword == null || userPassword.trim() == "") { document.getElementById("error").innerHTML = "密码不能为空"; return false; } if (rUserPassword.trim() == null || rUserPassword.trim() == "") { document.getElementById("error").innerHTML = "密码不能为空"; return false; } let reg1 = /(^\d{18}$)||(^\d{17}(\d|X|x)$)/; let reg2 = /(^\d{11}$)/; if(reg1.test(userIdCard) === false){ alert("身份证输入不合法"); return false; } if(reg2.test(userPhone) === false){ alert("手机号输入不合法"); return false; } if (rUserPassword != userPassword) { document.getElementById("error").innerHTML = "两次密码不相同"; return false; } return true; } </script> </table> <div align="center"> <input type="submit" class="btn btn-primary" value="保存"/> <span style="color: #dd1144" id="error">${tip}</span> </div> </div> </form> </div> 修改密码upPassword.jsp:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %> <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <style> * { background-color: #9acfea; } </style> <div class="data_list"> <h1>密码修改</h1> <div> <form method="post" action="common.action?action=sureUpPassword" οnsubmit="return checkThisFile()"> <table class="table table-striped table-bordered table-hover datatable"> <thead> <tr height="15px"> <th style="text-align: center;">输入新密码:</th> <th style="text-align: center;"><input name="userPassword" id="userPassword" type="password" width="400px" height="26px" style="border-bottom-right-radius: 3px"></th> </tr> <tr style="width: 500px"> <th style="text-align: center;">再次输入密码:</th> <th style="text-align: center;width: 70%"><input id="a" type="password" width="400px" height="26px";style="border-bottom-right-radius: 3px"> </th> </tr> <tr style="width: 500px"> <td></td> <td> <input type="submit" value="提交"> </td> </tr> <tr style="width: 500px"> <td></td> <td> <span style="color: #dd1144" id="error"></span> </td> </tr> </thead> </table> </form> <script> function checkThisFile() { let userPassword = document.getElementById("userPassword").value; let a = document.getElementById("a").value; // (stuCode == null || stuCode == "") if ((a==null||a.trim()=="")||(userPassword==null||userPassword.trim()=="")) { document.getElementById("error").innerHTML = "请输入两次完整密码"; return false; } else if(a!=userPassword){ document.getElementById("error").innerHTML = "两次密码不一致"; return false; }else{ return true; } } </script> </div> <div align="center"><font color="red"></font></div> </div> 老师查看考试信息task.jsp:
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>Title</title> <style> table{ width: 1300px; } tr,td{ border: grey 1px ; } td{ height: 40px; } table td{ height: 60px; vertical-align: middle!important; /*设置文字垂直居中*/ text-align: center; } tr,td{border-right:1px solid #888;border-bottom:1px solid #888;padding:5px 15px;} th{font-weight:bold;background:#ccc;} .con-b .row .lf{ width: 15%; text-align: center; padding: 10px; } .con-b .row .rg{ width: 85%; } .con-b tr:nth-of-type(odd){ background-color: #f2f2f2; } </style> <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> </head> <body> <table border="1" cellspacing="0" align="center" class="con-b"> <thead> <tr class="row" style="color: black;font-size: 25px"> <td class="lf">任务账户</td> <td class="lf">任务名称</td> <td class="lf">任务时间</td> <td class="lf">删除题目</td> <td class="lf">查看详细</td> </tr> </thead> <tbody> <c:forEach items="${arr}" var="task"> <tr> <td class="lf">${task.getTaskAccount()}</td> <td class="lf">${task.getTaskName()}</td> <td class="lf">${task.getTaskDate()}</td> <td class="lf"><img src="del.png" οnclick="deleteTishTask('${task.getTaskAccount()}')"></td> <td class="lf"><img style="width: 40px;height: 40px" src="detail.jpg" οnclick="skimDetail('${task.getTaskAccount()}')"></td> </tr> </c:forEach> </tbody> </table> </body> </html> <script> function deleteTishTask(taskAccount) { window.location.href = "tea.action?action=deleteTishTask&taskAccount="+taskAccount; } function skimDetail(taskAccount) { //查看这个任务的学生完成情况 window.location.href = "tea.action?action=goSkimDetail&taskAccount="+taskAccount; } </script> 学生考试信息studentTask.jsp:
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>Title</title> <style> table{ width: 1300px; } tr,td{ border: grey 1px ; } td{ height: 40px; } table td{ height: 60px; vertical-align: middle!important; /*设置文字垂直居中*/ text-align: center; } tr,td{border-right:1px solid #888;border-bottom:1px solid #888;padding:5px 15px;} th{font-weight:bold;background:#ccc;} .con-b .row .lf{ width: 15%; text-align: center; padding: 10px; } .con-b .row .rg{ width: 85%; } .con-b tr:nth-of-type(odd){ background-color: #f2f2f2; } </style> <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> </head> <body> <table border="1" cellspacing="0" align="center" class="con-b"> <thead> <%-- `taskAccount``studentAccount``studentAnswer``isFinish``isScore``userName``taskName`--%> <tr class="row" style="color: black;font-size: 25px" > <c:if test="${session_person.getUserIdentify()!=0}"><td class="lf">学生姓名</td></c:if> <td class="lf" style="width: 10%">题目</td> <td class="lf">答案</td> <td class="lf">是否完成</td> <td class="lf">分数</td> <c:if test="${session_person.getUserIdentify()==0}"><td class="lf">点击答题</td></c:if> <c:if test="${session_person.getUserIdentify()==1}"><td class="lf">点击批改</td></c:if> <td style="height:40px;width: 40px">删除</td> </tr> </thead> <tbody> <c:forEach items="${arr}" var="stuTask"> <tr> <c:if test="${session_person.getUserIdentify()!=0}"><td class="lf">${stuTask.getUserName()}</td></c:if> <td class="lf">${stuTask.getTaskName()}</td> <td class="lf">${stuTask.getStudentAnswer()}</td> <td class="lf"> <c:if test="${stuTask.getIsFinish()==0}"> <span style="color: red">未完成</span> </c:if> <c:if test="${stuTask.getIsFinish()==1}"> <span style="color: green">未批改</span> </c:if> <c:if test="${stuTask.getIsFinish()==2}"> <span style="color: orange">未完成</span> </c:if> </td> <td class="lf">${stuTask.getIsScore()}</td> <c:if test="${session_person.getUserIdentify()==0}"><td class="lf"><button οnclick="doAnswer('${stuTask.getTaskAccount()}','${stuTask.getIsFinish()}')">点击答题</button></td></c:if> <c:if test="${session_person.getUserIdentify()==1}"><td class="lf"><button οnclick="doFenshu('${stuTask.getTaskAccount()}',${stuTask.getStudentAccount()},'${stuTask.getIsFinish()}')">点击批改</button></td></c:if> <td> <img src="del.png" οnclick="delThisTask('${stuTask.getTaskAccount()}','${stuTask.getStudentAccount()}',${stuTask.getIsFinish()})"> </td> </tr> </c:forEach> </tbody> </table> </body> <script> function doFenshu(taskAccount,studentAccount,isFinish) { if(isFinish!=1){ alert("暂时没有批改权限") return; } window.open("student.action?action=doFenshu&taskAccount="+taskAccount+"&studentAccount="+studentAccount, null,"width=220,height=20,left=700,top=300", true); } function doAnswer(taskAccount,isFinish) { if(isFinish!=0){ alert("已经作答!") return; } window.open("student.action?action=doAnswer&taskAccount="+taskAccount+"", null,"width=700,height=400,left=400,top=150", true); } function delThisTask(taskAccount,studentAccount,isFinish) { if(${session_person.getUserIdentify()==1}){ if(isFinish==1){ alert("老师未作批改不能删除!"); }else { window.location.href = "tea.action?action=deleteTask&taskAccount="+taskAccount+"&studentAccount=" + studentAccount + "&isFinish=" + isFinish } }else { if(isFinish==2){ }else { alert("任务正在进行,不能删除"); } } alert("删除 题目好"+taskAccount+" 学生:" + studentAccount) } function upThisPerson(userAccount) { alert("修改:"+userAccount) } </script> </html>
老师添加题目addTask.jsp:
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>Title</title> <style> #content{ width: 1300px; height: 600px; float: right; margin-right: 40px; border: saddlebrown 1px solid; } #innerAddTaskFrame{ width: 1000px; height: 400px; margin-left: 100px; color: mediumslateblue; margin-top: 50px; font-size: 20px; } </style> </head> <body> <div id="content"> <div id="innerAddTaskFrame"> 请添加题目:<br><br> <form action="tea.action?action=addTask" method="post"> <textarea style="width: 800px;height: 160px;font-size: 25px;color: grey" rows="4" name="taskName"> </textarea> <br> <br> <br> <input style="margin-left: 350px" type="submit" value="点击添加"> </form> <span style="margin-left: 320px;font-size: 15px;color: red">${tip}</span> </div> </div> </body> </html> <script> function checkAddTask() { alert("hahah") return false; } </script>
detail.jsp:
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>Title</title> <style> table{ width: 1300px; } tr,td{ border: grey 1px ; } td{ height: 20px; } table td{ height: 20px; vertical-align: middle!important; /*设置文字垂直居中*/ /*text-align: center;*/ } /*tr,td{border-right:1px solid #888;border-bottom:1px solid #888;padding:5px 15px;}*/ th{font-weight:bold;background:#ccc;} .con-b .row .lf{ width: 15%; /*text-align: center;*/ padding: 10px; } .con-b .row .rg{ width: 85%; } .con-b tr:nth-of-type(odd){ background-color: #f2f2f2; } </style> <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> </head> <body> <table border="1" cellspacing="0" align="center" class="con-b"> <tbody> <tr class="row" style="color: black;font-size: 25px"> <td class="lf" >登录账户</td> <td class="lf">${session_person.getUserAccount()}</td> </tr> <tr class="row" style="color: black;font-size: 25px"> <td class="lf">姓名</td> <td class="lf">${session_person.getUserName()}</td> </tr> <tr class="row" style="color: black;font-size: 25px"> <td class="lf">性别</td> <td class="lf">${session_person.getUserSex()}</td> </tr> <tr class="row" style="color: black;font-size: 25px"> <td class="lf">出生日期</td> <td class="lf">${session_person.getUserBirthday()}</td> </tr> <tr class="row" style="color: black;font-size: 25px"> <td class="lf">身份证号码</td> <td class="lf">${session_person.getUserIdCard()}</td> </tr> <tr class="row" style="color: black;font-size: 25px"> <td class="lf"> <button οnclick="upPassword()">修改密码</button> </td> </tr> </tbody> </table> </body> </html> <script> function upPassword() { window.open("common.action?action=upPassword", null,"width=700,height=400,left=400,top=150", true); } </script>
作答doAnswer.jsp:
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>Title</title> <style> #content{ width:100%; height: 600px; margin-right: 40px; border: saddlebrown 1px solid; } #innerAddTaskFrame{ width: 100%; height: 400px; margin-left: 50px; color: mediumslateblue; margin-top: 50px; font-size: 20px; } </style> </head> <body> <div id="content"> <div id="innerAddTaskFrame"> 请作答:<br><br> <form action="student.action?action=dealAnswer&taskAccount=${taskAccount}" method="post" οnsubmit="return isDeal()"> <textarea id="answer" style="width: 600px;height: 160px;font-size: 25px;color: grey" rows="4" name="answer"> </textarea> <br> <br> <br> <input style="margin-left: 350px" type="submit" value="点击添加"> </form> <span style="margin-left: 320px;font-size: 15px;color: red">${tip}</span> </div> </div> <script> function isDeal() { let text = document.getElementById("answer").value; if(text.trim()==""||text==null){ alert("答案不能为空"); return false; }else { return true; } } </script> </body> </html> <script> </script>
获取分数getFenShu.jsp:
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>Title</title> </head> <body> <form action="student.action?action=getFenshu&taskAccount=${taskAccount}&studentAccount=${studentAccount}" method="post" οnsubmit="return checkFenshu()"> 分数:<input type="number" style="width: 150px;height: 20px" id="fenshu" name="fenshu"><br> <input style="position: center" type="submit" value="确认"> </form> </body> </html> <script> function getFenshu() { let fenshu = document.getElementById("fenshu").value; if(fenshu==null||fenshu.trim()==""){ alert("请输入分数!") return false; } if(fenshu<0||fenshu>100){ alert("分数不合法") return false; } return true; } </script>
index.jsp:
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>$Title$</title> </head> <body> <script> window.location.href = "userLogin.jsp"; </script> </body> </html>
我的老师myTeacher.jsp:
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>Title</title> <style> table{ width: 1300px; } tr,td{ border: grey 1px ; } td{ height: 40px; } table td{ height: 60px; vertical-align: middle!important; /*设置文字垂直居中*/ text-align: center; } tr,td{border-right:1px solid #888;border-bottom:1px solid #888;padding:5px 15px;} th{font-weight:bold;background:#ccc;} .con-b .row .lf{ width: 15%; text-align: center; padding: 10px; } .con-b .row .rg{ width: 85%; } .con-b tr:nth-of-type(odd){ background-color: #f2f2f2; } #content{ width: 1300px; height: 70px; float: right; border: grey 1px solid; margin-right: 40px; color: grey; font-size: 50px; } </style> <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> </head> <body> <br><br> <table border="1" cellspacing="0" align="center" class="con-b"> <thead> <%-- `userAccount``userName``userSex``userBirthday``userIdCard``userIdentify``userOtherName`--%> <tr class="row" style="color: black;font-size: 25px" > <td class="lf">老师账户</td> <td class="lf">老师姓名</td> <td class="lf" style="width: 10%">性别</td> <td class="lf">科目</td> <td class="lf">我的题目</td> <td style="width: 10%">操作</td> </tr> </thead> <tbody> <c:forEach items="${arr}" var="person"> <tr> <td class="lf">${person.getUserAccount()}</td> <td class="lf">${person.getUserName()}</td> <td class="lf">${person.getUserSex()}</td> <td class="lf">${person.getUserOtherName()}</td> <td class="lf"> <img style="width:40px;height: 40px" οnclick="goMyTask('${person.getUserAccount()}')" src="detail.jpg"> </td> <td><img style="width:40px;height: 40px" οnclick="deleteThisPerson('${person.getUserAccount()}')" src="del.png"></td> </tr> </c:forEach> </tbody> </table> </body> <script> function goMyTask(teacherAccount) { window.location.href = "student.action?action=goMyTeaTask&teacherAccount="+teacherAccount } function deleteThisPerson(teacherAccount) { window.location.href = "student.action?action=deleteMyTeacher&teacherAccount="+teacherAccount; } </script> </html> ssuccess.jsp:
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>Title</title> </head> <body> <p><span style="color: red">${tip}</span></p> </body> </html>
图片:
up.png:
head.png:
detail.png:
del.png:
addTeacher.png:
mStu.iml:
<?xml version="1.0" encoding="UTF-8"?> <module type="JAVA_MODULE" version="4"> <component name="FacetManager"> <facet type="web" name="Web"> <configuration> <descriptors> <deploymentDescriptor name="web.xml" url="file://$MODULE_DIR$/web/WEB-INF/web.xml" /> </descriptors> <webroots> <root url="file://$MODULE_DIR$/web" relative="/" /> </webroots> </configuration> </facet> <facet type="javaeeApplication" name="javaEEApplication"> <configuration> <descriptors> <deploymentDescriptor name="application.xml" url="file://$MODULE_DIR$/META-INF/application.xml" /> </descriptors> </configuration> </facet> </component> <component name="NewModuleRootManager" inherit-compiler-output="true"> <exclude-output /> <content url="file://$MODULE_DIR$"> <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" /> </content> <orderEntry type="inheritedJdk" /> <orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="library" name="lib" level="project" /> <orderEntry type="library" name="lib (2)" level="project" /> </component> </module>