基于javaweb+mysql的jsp+servlet学生选课系统(java+javaweb+jdbc)
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
功能介绍:
用户菜单、学生管理、教师管理、课程管理、成绩排名查询
基于javaweb+mysql的JSP+Servlet学生选课系统(java+javaweb+jdbc)
/*boolean f;
String message;
String tid = request.getParameter("tid");
teacher tea=new teacher();
f=tea.isValid(tid);
if(f==true){
tea.deleteTeacher(tid);
message="删除成功!!!";
doError(request,response,message);
}
else{
message="该教师不存在!!!";
doError(request,response,message);
}
}
public void doError(HttpServletRequest request,HttpServletResponse response,String str)
throws ServletException, IOException {
request.setAttribute("problem", str);
RequestDispatcher rd = getServletContext().getRequestDispatcher("/errorpage.jsp");
rd.forward(request, response);*/
}
/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occurs
*/
public void init() throws ServletException {
// Put your code here
}
}
public class delcourse extends HttpServlet {
public class m_updatescore extends HttpServlet {
/**
* Constructor of the object.
*/
public m_updatescore() {
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 {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out
.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
out.println("<HTML>");
// Put your code here
}
}
public class addstudent extends HttpServlet {
/**
* Constructor of the object.
*/
public addstudent() {
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
public class addscore extends HttpServlet {
private HttpServletRequest request;
/**
* Constructor of the object.
*/
public addscore() {
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 {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out
.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
* @throws ServletException if an error occurs
*/
public void init() throws ServletException {
// Put your code here
}
}
public class delstudent extends HttpServlet {
/**
* Constructor of the object.
*/
public delstudent() {
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 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");
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>");
out.print(" This is ");
out.print(this.getClass());
out.println(", using the POST method");
out.println(" </BODY>");
out.println("</HTML>");
out.flush();
out.close();
}
public void doError(HttpServletRequest request,HttpServletResponse response,String str)
throws ServletException, IOException {
request.setAttribute("problem", str);
request.getRequestDispatcher("/errorpage.jsp").forward(request, response);
}
/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occurs
*/
public void init() throws ServletException {
// Put your code here
}
}
* 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 {
doGet(request,response);
}
/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occurs
*/
public void init() throws ServletException {
// Put your code here
}
}
public class updatestudent extends HttpServlet {
/**
* Constructor of the object.
*/
public updatestudent() {
super();
}
/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=utf-8");
PrintWriter out = response.getWriter();
request.setCharacterEncoding("utf-8");
int pscore=Integer.parseInt(request.getParameter("pscore"));
int qscore=Integer.parseInt(request.getParameter("qscore"));
String sid=request.getParameter("sid");
String cid=request.getParameter("cid");
int grade=(int)(pscore*0.5+qscore*0.5);
double jpa=getJpa(request,response,grade);
coursescore cs=new coursescore();
cs.updatescore(sid, cid, pscore, qscore, grade, jpa);
coursescore sc=new coursescore();
ResultSet rs=sc.getone(sid);
try {
double sum_credit=0.0;//总学分
double sum_point=0.0;//总学分积点
while(rs.next()){
//String s_id=rs.getString("sid");
double credit1=rs.getDouble("credit");
double jpa1=rs.getDouble("jpa");
sum_point=sum_point+credit1*jpa1;
sum_credit=sum_credit+credit1;
}
double averagepoint=sum_point/sum_credit;
sc.addave_point(sid,averagepoint);
} catch (SQLException e) {
e.printStackTrace();
}
out.print("成绩修改成功!正在返回,请稍候。。。。。。");
response.setHeader("refresh", "1.5;url=/stu_score_ms/teacher/searchonescore.jsp?s_id="+sid);
}
public double getJpa(HttpServletRequest request,HttpServletResponse response,int grade)
throws ServletException, IOException {
double jpa;
if(grade>=90)
jpa=4.0;
else if(grade>=85)
jpa=3.7;
else if(grade>=82)
jpa=3.3;
else if(grade>=78)
jpa=3.0;
else if(grade>=75)
jpa=2.7;
else if(grade>=72)
jpa=2.3;
else if(grade>=68)
jpa=2.0;
out.println(", using the GET method");
out.println(" </BODY>");
out.println("</HTML>");
out.flush();
out.close();
}
/**
* 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();
request.setCharacterEncoding("utf-8");
int pscore=Integer.parseInt(request.getParameter("pscore"));
int qscore=Integer.parseInt(request.getParameter("qscore"));
String sid=request.getParameter("sid");
String cid=request.getParameter("cid");
int grade=(int)(pscore*0.5+qscore*0.5);
double jpa=getJpa(request,response,grade);
coursescore cs=new coursescore();
cs.updatescore(sid, cid, pscore, qscore, grade, jpa);
coursescore sc=new coursescore();
ResultSet rs=sc.getone(sid);
try {
double sum_credit=0.0;//总学分
double sum_point=0.0;//总学分积点
while(rs.next()){
//String s_id=rs.getString("sid");
double credit1=rs.getDouble("credit");
double jpa1=rs.getDouble("jpa");
sum_point=sum_point+credit1*jpa1;
sum_credit=sum_credit+credit1;
}
double averagepoint=sum_point/sum_credit;
sc.addave_point(sid,averagepoint);
} catch (SQLException e) {
e.printStackTrace();
}
public class addstudent extends HttpServlet {
/**
* Constructor of the object.
*/
public addstudent() {
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 {
response.setContentType("text/html;charset=utf-8");
PrintWriter out = response.getWriter();
request.setCharacterEncoding("utf-8");
String message;
String s_id=request.getParameter("sid");
String s_name=request.getParameter("sname");
String password=request.getParameter("password");
String s_class=request.getParameter("sclass");
String s_major=request.getParameter("smajor");
student stu=new student();
boolean f=stu.haslogin(s_id);
* 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 {
}
/**
* 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();
request.setCharacterEncoding("utf-8");
String s_id=request.getParameter("id");
String old;
String pw1=null;
String pw2=null;
old=request.getParameter("oldpassword");
pw1=request.getParameter("password1");
pw2=request.getParameter("password2");
//查询原密码
String sql="select password from student where id = '"+s_id+"'";
sqlBean db=new sqlBean();
ResultSet rs = db.executeQuery(sql);
String dbOldPwd = "";
try {
if(rs.next()){
out.println(" <BODY>");
out.print(" This is ");
out.print(this.getClass());
out.println(", using the POST method");
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 addcourse extends HttpServlet {
/**
* Constructor of the object.
*/
public addcourse() {
super();
}
/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
/**
doError(request,response,"用户名或密码错误!");
}
}
catch(Exception g){
System.err.println("用户名或密码错误!"+g.getMessage());
g.printStackTrace();
doError(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 goo(HttpServletRequest request,HttpServletResponse response,String kind)
throws ServletException,IOException{
if(kind.equals("student")){
//控制页面跳转
RequestDispatcher rd=getServletContext().getRequestDispatcher("/student/student.jsp");
rd.forward(request, response);
}
if(kind.equals("teacher")){
RequestDispatcher rd=getServletContext().getRequestDispatcher("/teacher/teacher.jsp");
rd.forward(request, response);
}
if(kind.equals("manager")){
RequestDispatcher rd=getServletContext().getRequestDispatcher("/manager/manager.jsp");
rd.forward(request, response);
}
}
public void doError(HttpServletRequest request,HttpServletResponse response,String str)
throws ServletException,IOException{
request.setAttribute("problem", str);
getServletConfig().getServletContext().getRequestDispatcher("/errorpage.jsp").forward(request, response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request,response);
}
HttpSession session1 =request.getSession(true);
String cno_id=(String)session1.getAttribute("cno_id");
String cla_id=(String)session1.getAttribute("cla_id");
String kai_id=(String)session1.getAttribute("kai_id");
int num=Integer.parseInt((String)session1.getAttribute("num"));
int i=1,j=200;
coursescore sco=new coursescore();
studentcourse stucou=new studentcourse();
ResultSet rs=stucou.getStuCou(cno_id, cla_id, kai_id);
try{
while(rs.next()&i<=num){
String cname=rs.getString("cname");
double credit=rs.getDouble("credit");
String s_id= rs.getString("sid");
String ps=request.getParameter(Integer.toString(i));
String qs=request.getParameter(Integer.toString(j));
double pscore=Double.valueOf(ps);
double qscore=Double.valueOf(qs);
if(ps.equals(""))
pscore=0;
if(qs.equals(""))
qscore=0;
int grade=(int) (pscore*0.3+qscore*0.7);
double kpoint1=getJpa(request,response,grade);
double kpoint=credit*kpoint1;
sco.setCid(cno_id);
sco.setCname(cname);
sco.setCredit(credit);
sco.setSid(s_id);
sco.setPscore(pscore);
sco.setQscore(qscore);
sco.setGrade(grade);
sco.setJpa(kpoint);
sco.addScore();
i++; j++;
}
doError(request,response,"添加成功!!!");
}
catch(SQLException e){
System.err.println("添加有误!"+e.getMessage());
}
public class updateTpassword extends HttpServlet {
/**
* Constructor of the object.
*/
public updateTpassword() {
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 {
}
/**
String s_name=request.getParameter("sname");
String password=request.getParameter("password");
String s_class=request.getParameter("sclass");
String s_major=request.getParameter("smajor");
student stu=new student();
boolean f=stu.haslogin(s_id);
if(f==true){
message="对不起,该学号已被注册!";
doError(request,response,message);
}
else if(s_id.equals("")){
message="学号不能为空,请重新填写!";
doError(request,response,message);
}
else if(s_name.equals("")){
message="姓名不能为空,请重新填写!";
doError(request,response,message);
}
else if(password.equals("")){
message="密码不能为空,请重新填写!";
doError(request,response,message);
}
else{
stu.setSid(s_id);
stu.setSname(s_name);
stu.setSpassword(password);
stu.setSclass(s_class);
stu.setSmajor(s_major);
stu.addStudent();
out.print("学生添加成功!正在返回,请稍候……");
response.setHeader("refresh", "1.5;url=/stu_score_ms/manager/showstudent.jsp");
}
}
public void doError(HttpServletRequest request,HttpServletResponse response,String str)
throws ServletException,IOException{
request.setAttribute("problem", str);
RequestDispatcher rd = getServletContext().getRequestDispatcher("/errorpage.jsp");
rd.forward(request, response);
}
/**
* @throws ServletException if an error occurs
*/
public void init() throws ServletException {
// Put your code here
}
}
public class m_selectcourse extends HttpServlet {
/**
* Constructor of the object.
*/
public m_selectcourse() {
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)