基于javaweb+mysql的jsp+servlet学生选课信息管理系统(java+jsp+servlet+javascript+mysql)
私信源码获取及调试交流
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb的JSP+Servlet学生选课信息管理系统(java+jsp+servlet+javascript+mysql)
项目介绍
本项目包含学生,教师两个角色,然后学生可以查看选课信息,执行选课操作,老师可以修改学生的信息等等。
环境需要
1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。 2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA; 3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可 4.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS; 5.数据库:MySql 5.7版本; 6.是否Maven项目:否;
技术栈
JSP+CSS+JavaScript+Servlet+mysql
使用说明
- 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件; 2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven; 若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行; 3. 将项目中conn/Conn.java配置文件中的数据库配置改为自己的配置; 4. 运行项目,输入localhost:8080/Ten 登录 注:Tomcat中设置路径必须为/Ten,否则会有异常 学生账号/密码:1514010919/123456 老师账号/密码:1/admin
response.sendRedirect("/Ten/stu/student.jsp");
}else{
out.println("S用户名或密码不正确,请核对后重试!!");
response.setHeader("refresh","2;url=/Ten/Login.jsp");
}
}else{
out.println("错误!请登录!");
response.setHeader("refresh","2;url=/Ten/Login.jsp");
}
}catch(Exception e){ e.printStackTrace();response.sendRedirect("/Ten/Login.jsp");}
out.flush();
out.close();
}
/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occurs
*/
public void init() throws ServletException {
// Put your code here
}
}
public class serDoUpdateClass extends HttpServlet {
/**
* Constructor of the object.
*/
public serDoUpdateClass() {
super();
}
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
this.doPost(request, response);
}
/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=utf-8");
HttpSession session = request.getSession();
PrintWriter out = response.getWriter();
//response.setCharacterEncoding("utf-8");
//response.setHeader("content-type","text/html;charset=utf-8");
try{
int username = Integer.parseInt(request.getParameter("username"));
String password = request.getParameter("password");
String type = null;
if(request.getParameter("type")!=null)
type = request.getParameter("type");
if(type.equals("tea")){//判断是否为老师
Teacher tea = new Teacher(username,null,password);
DaoTea logint = new DaoTea();
tea = logint.loginTea(tea);
if(tea!=null){
public serDoLogout() {
super();
}
/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
this.doPost(request, response);
}
/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
HttpSession session = request.getSession();
try{
// Object tea = session.getAttribute("teacher");
// Object stu = session.getAttribute("student");
session.removeAttribute("teacher");
@SuppressWarnings("serial")
public class serInsertStu extends HttpServlet {
/**
* Constructor of the object.
*/
public serInsertStu() {
super();
}
/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
this.doPost(request, response);
}
/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=utf-8");
PrintWriter out = response.getWriter();
out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
}else {
out.println("<h2><center>选课失败</cneter></h2>");
response.setHeader("refresh", "2;url=../stu/choiceCou.jsp");
}
}catch(Exception e){e.printStackTrace();out.println("选课失败!");response.setHeader("refresh", "2;url=../stu/choiceCou.jsp");}
out.println(" </BODY>");
out.println("</HTML>");}
out.flush();
out.close();
}
/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occurs
*/
public void init() throws ServletException {
// Put your code here
}
}
public class serQuerySc extends HttpServlet {
/**
* Constructor of the object.
*/
public serQuerySc() {
super();
}
/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
this.doPost(request, response);
}
/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=utf-8");
PrintWriter out = response.getWriter();
out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
out.println("<HTML>");
out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>");
out.println(" <BODY><center>");
try{
request.setCharacterEncoding("utf-8");
Course cou = new Course(request.getParameter("Cname"),request.getParameter("Ccredit"));
DaoCou insert = new DaoCou();
int rs = insert.insertCou(cou);
if(rs!=0){
out.println("添加成功:"+cou.getCNo());
}else{
out.println("添加失败"+cou.getCNo());
}
response.sendRedirect("/Ten/tea/selectCou.jsp");
public class serInsertSc extends HttpServlet {
/**
* Constructor of the object.
*/
public serInsertSc() {
super();
}
/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
this.doPost(request, response);
}
/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=utf-8");
/******************************************************************************/
HttpSession session = request.getSession();
PrintWriter out = response.getWriter();
Student stu = null;
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
this.doPost(request, response);
}
/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=utf-8");
PrintWriter out = response.getWriter();
HttpSession session = request.getSession();
/************************************************************/
if(session.getAttribute("teacher")==null){
response.sendRedirect("../Login.jsp");
}else{
Teacher tea = (Teacher) session.getAttribute("teacher");
/*************************************************************/
out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
out.println("<HTML>");
out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>");
out.println(" <BODY>");
try{
request.setCharacterEncoding("utf-8");
String queryKey = request.getParameter("queryKey");//查询关键字
int type = 20;//查询类型,默认为20,不是1-6就好
if(request.getParameter("type")!=null){
type = Integer.parseInt(request.getParameter("type"));
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=utf-8");
PrintWriter out = response.getWriter();
/**************************************************************/
HttpSession session = request.getSession();
if(session.getAttribute("teacher")==null){
response.sendRedirect("../Login.jsp");
}else{
/**************************************************************/
out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
out.println("<HTML>");
out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>");
out.println(" <BODY>");
try{
int sno = Integer.parseInt(request.getParameter("sno"));
int cno = Integer.parseInt(request.getParameter("cno"));
String classroom = request.getParameter("classroom");
DaoSc update = new DaoSc();
SC sc = new SC();
sc.setSNo(sno);
sc.setCNo(cno);
sc.setClassroom(classroom);
int rs = update.updateClass(sc);
if(rs!=0) {
System.out.println("classroom update over!!");
out.println("<center><h2>教室修改成功</h2></center>");
}else{
out.println("<center><h2>教室修改失败</h2></center>");
}
response.setHeader("refresh","2;url=/Ten/tea/Query.jsp?type="+request.getParameter("type")+"&query="+request.getParameter("key")+"");
}catch(Exception e){e.printStackTrace();}
out.println(" </BODY>");
out.println("</HTML>");
}
out.flush();
out.close();
}
/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occurs
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
this.doPost(request, response);
}
/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=utf-8");
PrintWriter out = response.getWriter();
/**************************************************************/
HttpSession session = request.getSession();
if(session.getAttribute("teacher")==null){
response.sendRedirect("../Login.jsp");
}else{
/**************************************************************/
out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
out.println("<HTML>");
out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>");
out.println(" <BODY>");
try{
int sno = Integer.parseInt(request.getParameter("sno"));
int cno = Integer.parseInt(request.getParameter("cno"));
String classroom = request.getParameter("classroom");
DaoSc update = new DaoSc();
SC sc = new SC();
sc.setSNo(sno);
sc.setCNo(cno);
sc.setClassroom(classroom);
int rs = update.updateClass(sc);
public class serDoUpdateClass extends HttpServlet {
/**
* Constructor of the object.
*/
public serDoUpdateClass() {
super();
}
/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
out.close();
}
/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occurs
*/
public void init() throws ServletException {
// Put your code here
}
}
@SuppressWarnings("serial")
public class serDoLogout extends HttpServlet {
/**
* Constructor of the object.
*/
public serDoLogout() {
super();
}
/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
}else {
out.println("<h2><center>你选择的课程超过上限"+Student.MAXscore+"分!</cneter></h2>");
response.setHeader("refresh", "2;url=../stu/choiceCou.jsp");
}
}else {
out.println("<h2><center>选课失败</cneter></h2>");
response.setHeader("refresh", "2;url=../stu/choiceCou.jsp");
}
}catch(Exception e){e.printStackTrace();out.println("选课失败!");response.setHeader("refresh", "2;url=../stu/choiceCou.jsp");}
out.println(" </BODY>");
out.println("</HTML>");}
out.flush();
out.close();
}
/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occurs
*/
public void init() throws ServletException {
// Put your code here
}
}
public class serQuerySc extends HttpServlet {
/**
* Constructor of the object.
*/
public serQuerySc() {
super();
out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
out.println("<HTML>");
out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>");
out.println(" <BODY>");
try{
int sno = Integer.parseInt(request.getParameter("sno"));
int cno = Integer.parseInt(request.getParameter("cno"));
DaoSc update = new DaoSc();
SC sc = update.selectone(sno,cno);
if(sc!=null){
request.setAttribute("room", sc);
request.getRequestDispatcher("/tea/updateRoom.jsp?type="+request.getParameter("type")+"&key="+request.getParameter("key")+"").forward(request, response);
}else{
out.println("<h2>查询失败,请稍后重试</h2>");
response.setHeader("refresh", "2;url=serQuerySc");
}
}catch(Exception e){e.printStackTrace();}
out.println(" </BODY>");
out.println("</HTML>");
}
out.flush();
out.close();
}
/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occurs
*/
public void init() throws ServletException {
// Put your code here
}
}
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=utf-8");
/******************************************************************************/
HttpSession session = request.getSession();
PrintWriter out = response.getWriter();
Student stu = null;
if(session.getAttribute("student")==null){
response.sendRedirect("../Login.jsp");
}else{
stu = (Student) session.getAttribute("student");
//out.println(stu.getSNo()+"SNO");
/******************************************************************************/
out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
out.println("<HTML>");
out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>");
out.println(" <BODY>");
try{
String choiceR[] = request.getParameterValues("choiceCou");
DaoStu selects = new DaoStu();
DaoCou selectc = new DaoCou();
Student stu2 = selects.selectScre(stu);
float scredit = stu2.getScredit();//学生已经选到的学分数
int sno = stu.getSNo();
if(choiceR.length!=0){//空异常是什么鬼啊啊啊
SC sc[] = new SC[choiceR.length];
for(int i =0;i<choiceR.length;i++){
sc[i] = new SC();
sc[i].setSNo(sno);
sc[i].setCNo(Integer.parseInt(choiceR[i]));
sc[i].setClassroom("0");//上课教室应该如何录入???默认为0,表示没有教室
scredit += selectc.selectScre(sc[i].getSNo());//学生待选课程+学生已选课程学分
}
if(scredit<=Student.MAXscore){
@SuppressWarnings("serial")
public class serDoLogout extends HttpServlet {
/**
* Constructor of the object.
*/
public serDoLogout() {
super();
}
/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
this.doPost(request, response);
}
/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
this.doPost(request, response);
}
/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=utf-8");
/******************************************************************************/
HttpSession session = request.getSession();
PrintWriter out = response.getWriter();
Student stu = null;
if(session.getAttribute("student")==null){
response.sendRedirect("../Login.jsp");
}else{
stu = (Student) session.getAttribute("student");
//out.println(stu.getSNo()+"SNO");
/******************************************************************************/
out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
out.println("<HTML>");
out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>");
out.println(" <BODY>");
try{
String choiceR[] = request.getParameterValues("choiceCou");
DaoStu selects = new DaoStu();
DaoCou selectc = new DaoCou();
Student stu2 = selects.selectScre(stu);
float scredit = stu2.getScredit();//学生已经选到的学分数
int sno = stu.getSNo();
if(choiceR.length!=0){//空异常是什么鬼啊啊啊
SC sc[] = new SC[choiceR.length];
for(int i =0;i<choiceR.length;i++){
sc[i] = new SC();
sc[i].setSNo(sno);
sc[i].setCNo(Integer.parseInt(choiceR[i]));
sc[i].setClassroom("0");//上课教室应该如何录入???默认为0,表示没有教室
scredit += selectc.selectScre(sc[i].getSNo());//学生待选课程+学生已选课程学分
}
if(scredit<=Student.MAXscore){
DaoSc insert = new DaoSc();
int rs[] = insert.insertSc(sc),sum =0;
for(int i =0;i<rs.length;i++){
if(rs[i]==0) System.out.println("rs"+i+"is null !!");
sum += rs[i];