java 选课系统_简单的JAVAWeb选课系统

这是一个基于Java的简单选课系统,包括管理员、教师和学生角色。管理员可管理学生和教师信息,教师能修改个人信息、添加课程并查看自己的课程,而学生则能修改个人信息和选课。系统通过Guanli包中的类进行数据操作,使用Login包的DBUtil连接数据库。
摘要由CSDN通过智能技术生成

该系统管理员可以添加和删除学生、教师,教师可以修改自己信息、添加课程、浏览自己课程,学生可以修改自己的信息、选课、浏览全部课程。

首先展示文件:

d83204266a1e84646ee3a5f71a3cfc15.png

d1c0233b78e4348a6c40389ef903b28b.png

a8bf7530eef63499770b436ef7dda29d.png

然后就是一次展示代码:

Guanli包中代码:

package Guanli;

import java.sql.Connection;

import java.sql.SQLException;

import java.sql.Statement;

import Login.DBUtil;public classAdd {publicboolean add(String table,AddService en)

{

boolean c=false;

String sql="insert into"+table+"(username,password,power,name) values('"+en.getUsername()+"','"+en.getPassword()+"','"+en.getPower()+"','"+en.getName()+"');";

Connection conn=DBUtil.getConn();

Statement state=null;try{

state=conn.createStatement();int num=state.executeUpdate(sql);if(num!=0)

c=true;

state.close();

conn.close();

}catch(SQLException e) {//TODO Auto-generated catch block//e.printStackTrace();

}returnc;

}publicboolean add(String table,TeacherService en)

{

boolean c=false;

String sql="insert into"+table+"(gonghao,xingming,xingbie,xueyuan,zhicheng) values('"+en.getGonghao()+"','"+en.getXingming()+"','"+en.getXingbie()+"','"+en.getXueyuan()+"','"+en.getZhicheng()+"');";

Connection conn=DBUtil.getConn();

Statement state=null;try{

state=conn.createStatement();int num=state.executeUpdate(sql);if(num!=0)

c=true;

state.close();

conn.close();

}catch(SQLException e) {//TODO Auto-generated catch block//e.printStackTrace();

}returnc;

}publicboolean add(String table,StudentService en)

{

boolean c=false;

String sql="insert into"+table+"(xuehao,xingming,xingbie,banji,zhuanye) values('"+en.getXuehao()+"','"+en.getXingming()+"','"+en.getXingbie()+"','"+en.getBanji()+"','"+en.getZhuanye()+"');";

Connection conn=DBUtil.getConn();

Statement state=null;try{

state=conn.createStatement();int num=state.executeUpdate(sql);if(num!=0)

c=true;

state.close();

conn.close();

}catch(SQLException e) {//TODO Auto-generated catch block//e.printStackTrace();

}returnc;

}

}

package Guanli;

import java.sql.Time;

import java.text.SimpleDateFormat;

import java.util.Date;public classAddService {

String username;

String password;

String name;publicString getName() {returnname;

}public voidsetName(String name) {this.name =name;

}intpower;publicString getUsername() {returnusername;

}public voidsetUsername(String username) {this.username =username;

}publicString getPassword() {returnpassword;

}public voidsetPassword(String password) {this.password =password;

}public intgetPower() {returnpower;

}public void setPower(intpower) {this.power =power;

}

}

packageGuanli;importjava.awt.Desktop.Action;importjava.io.IOException;importjavax.servlet.ServletException;importjavax.servlet.annotation.WebServlet;importjavax.servlet.http.HttpServlet;importjavax.servlet.http.HttpServletRequest;importjavax.servlet.http.HttpServletResponse;importLogin.Power;importLogin.Select;/*** Servlet implementation class RegisterServlet*/@WebServlet("/RegisterServlet")public class RegisterServlet extendsHttpServlet {private static final long serialVersionUID = 1L;/***@seeHttpServlet#HttpServlet()*/

publicRegisterServlet() {super();//TODO Auto-generated constructor stub

}protected void service(HttpServletRequest arg0, HttpServletResponse arg1) throwsServletException, IOException

{

Select s=newSelect();

arg0.setCharacterEncoding("utf-8");

arg1.setCharacterEncoding("utf-8");booleanflag;

String function=arg0.getParameter("method");if(function.equals("teacher"))

{

AddService as=newAddService();

Add a=newAdd();

String username;

username=arg0.getParameter("username");

as.setUsername(username);

String password;

password=arg0.getParameter("password");

as.setPassword(password);int num=1;

as.setPower(num);

TeacherService ts=newTeacherService();

String gonghao;

gonghao=arg0.getParameter("gonghao");

ts.setGonghao(gonghao);

String xingming;

xingming=arg0.getParameter("xingming");

ts.setXingming(xingming);

as.setName(xingming);

String xingbie;

xingbie=arg0.getParameter("xingbie");

ts.setXingbie(xingbie);

String xueyuan;

xueyuan=arg0.getParameter("xueyuan");

ts.setXueyuan(xueyuan);

String zhicheng;

zhicheng=arg0.getParameter("zhicheng");

ts.setZhicheng(zhicheng);

a.add("login", as);

a.add("teacher", ts);

arg0.setAttribute("message","添加成功");

arg0.getRequestDispatcher("Right.jsp").forward(arg0, arg1);

}if(function.equals("student"))

{

AddService as=newAddService();

Add a=newAdd();

String username;

username=arg0.getParameter("username");

as.setUsername(username);

String password;

password=arg0.getParameter("password");

as.setPassword(password);int num=2;

as.setPower(num);

StudentService ss=newStudentService();

String xuehao;

xuehao=arg0.getParameter("xuehao");

ss.setXuehao(xuehao);

String xingming;

xingming=arg0.getParameter("xingming");

ss.setXingming(xingming);

as.setName(xingming);

String xingbie;

xingbie=arg0.getParameter("xingbie");

ss.setXingbie(xingbie);

String banji;

banji=arg0.getParameter("banji");

ss.setBanji(banji);

String zhuanye;

zhuanye=arg0.getParameter("zhuanye");

ss.setZhuanye(zhuanye);

a.add("student", ss);

a.add("login", as);

arg0.setAttribute("message","添加成功");

arg0.getRequestDispatcher("Right.jsp").forward(arg0, arg1);

}

}/***@seeHttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)*/

protected void doGet(HttpServletRequest request, HttpServletResponse response) throwsServletException, IOException {//TODO Auto-generated method stub

response.getWriter().append("Served at: ").append(request.getContextPath());

}/***@seeHttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)*/

protected void doPost(HttpServletRequest request, HttpServletResponse response) throwsServletException, IOException {//TODO Auto-generated method stub

doGet(request, response);

}

}

packageGuanli;public classStudentService {

String xuehao;

String xingming;

String xingbie;

String banji;

String zhuanye;publicString getXuehao() {returnxuehao;

}public voidsetXuehao(String xuehao) {this.xuehao =xuehao;

}publicString getXingming() {returnxingming;

}public voidsetXingming(String xingming) {this.xingming =xingming;

}publicString getXingbie() {returnxingbie;

}public voidsetXingbie(String xingbie) {this.xingbie =xingbie;

}publicString getBanji() {returnbanji;

}public voidsetBanji(String banji) {this.banji =banji;

}publicString getZhuanye() {returnzhuanye;

}public voidsetZhuanye(String zhuanye) {this.zhuanye =zhuanye;

}

}

packageGuanli;public classTeacherService {

String gonghao;

String xingming;

String xingbie;

String xueyuan;

String zhicheng;publicString getGonghao() {returngonghao;

}public voidsetGonghao(String gonghao) {this.gonghao =gonghao;

}publicString getXingming() {returnxingming;

}public voidsetXingming(String xingming) {this.xingming =xingming;

}publicString getXingbie() {returnxingbie;

}public voidsetXingbie(String xingbie) {this.xingbie =xingbie;

}publicString getXueyuan() {returnxueyuan;

}public voidsetXueyuan(String xueyuan) {this.xueyuan =xueyuan;

}publicString getZhicheng() {returnzhicheng;

}public voidsetZhicheng(String zhicheng) {this.zhicheng =zhicheng;

}

}

Login包里的文件:

packageLogin;importjava.sql.Connection;importjava.sql.DriverManager;importjava.sql.PreparedStatement;importjava.sql.ResultSet;importjava.sql.SQLException;importjava.sql.Statement;/*** 数据库连接工具

*@authorHu

**/

public classDBUtil {public static String db_url = "jdbc:mysql://localhost:3306/jianmintest?useSSL=false&serverTimezone=UTC&characterEncoding=UTF-8";public static String db_user = "root";public static String db_pass = "20183629";public staticConnection getConn () {

Connection conn= null;try{

Class.forName("com.mysql.jdbc.Driver");//加载驱动

conn =DriverManager.getConnection(db_url, db_user, db_pass);

}catch(Exception e) {

e.printStackTrace();

}returnconn;

}/*** 关闭连接

*@paramstate

*@paramconn*/

public static voidclose (Statement state, Connection conn) {if (state != null) {try{

state.close();

}catch(SQLException e) {

e.printStackTrace();

}

}if (conn != null) {try{

conn.close();

}catch(SQLException e) {

e.printStackTrace();

}

}

}public static voidclose (ResultSet rs, Statement state, Connection conn) {if (rs != null) {try{

rs.close();

}catch(SQLException e) {

e.printStackTrace();

}

}if (state != null) {try{

state.close();

}catch(SQLException e) {

e.printStackTrace();

}

}if (conn != null) {try{

conn.close();

}catch(SQLException e) {

e.printStackTrace();

}

}

}public static void main(String[] args) throwsSQLException {

Connection conn=getConn();

PreparedStatement pstmt= null;

ResultSet rs= null;

String sql="select * from course";

pstmt=conn.prepareStatement(sql);

rs=pstmt.executeQuery();if(rs.next()){

System.out.println("空");

}else{

System.out.println("不空");

}

}

}

packageLogin;importjava.io.IOException;importjavax.servlet.ServletException;importjavax.servlet.annotation.WebServlet;importjavax.servlet.http.HttpServlet;importjavax.servlet.http.HttpServletRequest;importjavax.servlet.http.HttpServletResponse;/*** Servlet implementation class LoginServlet*/@WebServlet("/LoginServlet")public class LoginServlet extendsHttpServlet {private static final long serialVersionUID = 1L;/***@seeHttpServlet#HttpServlet()*/

publicLoginServlet() {super();//TODO Auto-generated constructor stub

}protected void service(HttpServletRequest arg0, HttpServletResponse arg1) throwsServletException, IOException

{

Select s=newSelect();

arg0.setCharacterEncoding("utf-8");

arg1.setCharacterEncoding("utf-8");booleanflag;

String function=arg0.getParameter("method");if(function.equals("login"))

{

String username;

username=arg0.getParameter("username");

String password;

password=arg0.getParameter("password");

String power;

power=arg0.getParameter("power");int num=Integer.parseInt(power);

flag=s.select("login", username, password,num);

Power.setFlag(num);if(flag)

{

arg0.setAttribute("message","登录成功");

arg0.getRequestDispatcher("Home.jsp").forward(arg0, arg1);

}else{

arg0.setAttribute("message", "账号或密码有误");

arg0.getRequestDispatcher("Login.jsp").forward(arg0, arg1);

}

}

}/***@seeHttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)*/

protected void doGet(HttpServletRequest request, HttpServletResponse response) throwsServletException, IOException {//TODO Auto-generated method stub

response.getWriter().append("Served at: ").append(request.getContextPath());

}/***@seeHttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)*/

protected void doPost(HttpServletRequest request, HttpServletResponse response) throwsServletException, IOException {//TODO Auto-generated method stub

doGet(request, response);

}

}

packageLogin;public classPower {static intflag;public static intgetFlag() {returnflag;

}public static void setFlag(intflag) {

Power.flag=flag;

}staticString xingming;public staticString getXingming() {returnxingming;

}public static voidsetXingming(String xingming) {

Power.xingming=xingming;

}staticString username;public staticString getUsername() {returnusername;

}public static voidsetUsername(String username) {

Power.username=username;

}

}

packageLogin;importjava.sql.Connection;importjava.sql.ResultSet;importjava.sql.SQLException;importjava.sql.Statement;public classSelect {public boolean select(String table,String username,String password,intnum)

{boolean f=false;

Connection conn=DBUtil.getConn();

Statement state=null;try{

state=conn.createStatement();

String sql="select * from "+table;

ResultSet rs=state.executeQuery(sql);while(rs.next())

{if(username.equals(rs.getString(1))&&password.equals(rs.getString(2))&&rs.getInt(4)==num)

{

Power.setXingming(rs.getString(3));

Power.setUsername(rs.getString(1));

System.out.println(Power.getXingming());

f=true;

}

}

rs.close();

state.close();

conn.close();

}catch(Exception e)

{

}returnf;

}

}

Student包中的代码:

packageStudent;importjava.sql.Connection;importjava.sql.SQLException;importjava.sql.Statement;importLogin.DBUtil;public classAdd {public booleanadd(String table,Jieguo en)

{boolean c=false;

String sql="insert into "+table+"(kechengbianhao,gonghao,jiaoshixingming,xuehao,xingming) values('"+en.getKechengbianhao()+"','"+en.getGonghao()+"','"+en.getJiaoshixingming()+"','"+en.getXuehao()+"','"+en.getXingming()+"');";

System.out.println(sql);

Connection conn=DBUtil.getConn();

Statement state=null;try{

state=conn.createStatement();int num=state.executeUpdate(sql);if(num!=0)

c=true;

state.close();

conn.close();

}catch(SQLException e) {//TODO Auto-generated catch block//e.printStackTrace();

}returnc;

}

}

packageStudent;importjava.sql.Connection;importjava.sql.SQLException;importjava.sql.Statement;importLogin.DBUtil;public classChange {public booleanchange(String table,String lie,String lie0,String gai,String biao)

{

Connection conn=DBUtil.getConn();

Statement state=null;try{

state=conn.createStatement();

String sql="update "+table+" set "+lie+"='"+gai+"' where "+lie0+"='"+biao+"'";

System.out.println(sql);

state.executeUpdate(sql);

state.close();

conn.close();

}catch(SQLException e) {//TODO Auto-generated catch block

e.printStackTrace();

}return true;

}

}

packageStudent;importjava.sql.Connection;importjava.sql.ResultSet;importjava.sql.Statement;importLogin.DBUtil;public classFind {public booleanfind(String table,String id)

{booleanc;

Connection conn=DBUtil.getConn();

Statement state=null;try{

state=conn.createStatement();

String sql="select * from "+table+" where xingming ='"+id+"'";

ResultSet rs=state.executeQuery(sql);while(rs.next())

{

Service.setXuehao(rs.getString(1));

Service.setXingming(rs.getString(2));

Service.setXingbie(rs.getString(3));

Service.setBanji(rs.getString(4));

Service.setZhuanye(rs.getString(5));

}

rs.close();

state.close();

conn.close();

System.out.println("over");

}catch(Exception e)

{

}return true;

}public voidfindclass(String table,String id)

{booleanc;

Connection conn=DBUtil.getConn();

Statement state=null;try{

state=conn.createStatement();

String sql="select * from "+table+" where kechengbianhao ='"+id+"'";

ResultSet rs=state.executeQuery(sql);while(rs.next())

{

KechengService.setKechengbianhao(rs.getString(1));

KechengService.setKechengmingcheng(rs.getString(2));

KechengService.setRenkejiaoshi(rs.getString(4));

KechengService.setRenshushangxian(rs.getInt(5));

KechengService.setXianyourenshu(rs.getInt(6));

}

rs.close();

state.close();

conn.close();

System.out.println("over");

}catch(Exception e)

{

}

}public voidfindjiaoshi(String table,String id)

{booleanc;

Connection conn=DBUtil.getConn();

Statement state=null;try{

state=conn.createStatement();

String sql="select * from "+table+" where gonghao ='"+id+"'";

ResultSet rs=state.executeQuery(sql);while(rs.next())

{

TeacherService.setGonghao(rs.getString(1));

TeacherService.setXingming(rs.getString(2));

TeacherService.setXingbie(rs.getString(3));

TeacherService.setXueyuan(rs.getString(4));

TeacherService.setZhicheng(rs.getString(5));

}

rs.close();

state.close();

conn.close();

System.out.println("over");

}catch(Exception e)

{

}

}

}

packageStudent;importjava.sql.Connection;importjava.sql.PreparedStatement;importjava.sql.ResultSet;importjava.util.ArrayList;importjava.util.List;importLogin.DBUtil;importTeacher.KechengService;public classGet {public static ListgetAll()

{

List list=new ArrayList();

Connection conn=DBUtil.getConn();

PreparedStatement state=null;

ResultSet rs=null;

String sql="select * from class";try{

state=conn.prepareStatement(sql);

rs=state.executeQuery();while(rs.next())

{if(rs.getInt(5)>rs.getInt(6))

{

KechengService user=newKechengService();

user.setKechengbianhao(rs.getString(1));

user.setKechengmingcheng(rs.getString(2));

user.setGonghao(rs.getString(3));

user.setRenkejiaoshi(rs.getString(4));

user.setXianyourenshu(rs.getInt(6));

list.add(user);

}

}

rs.close();

state.close();

conn.close();

}catch(Exception e)

{

}if(list!=null) {returnlist;

}else{return null;

}

}public static ListgetAll0()

{

List list=new ArrayList();

Connection conn=DBUtil.getConn();

PreparedStatement state=null;

ResultSet rs=null;

String sql="select * from class";try{

state=conn.prepareStatement(sql);

rs=state.executeQuery();while(rs.next())

{

KechengService user=newKechengService();

user.setKechengbianhao(rs.getString(1));

user.setKechengmingcheng(rs.getString(2));

user.setGonghao(rs.getString(3));

user.setRenkejiaoshi(rs.getString(4));

user.setXianyourenshu(rs.getInt(6));

list.add(user);

}

rs.close();

state.close();

conn.close();

}catch(Exception e)

{

}if(list!=null) {returnlist;

}else{return null;

}

}

}

packageStudent;public classJieguo {

String kechengbianhao;

String jiaoshixingming;

String gonghao;

String xuehao;

String xingming;publicString getGonghao() {returngonghao;

}public voidsetGonghao(String gonghao) {this.gonghao =gonghao;

}publicString getKechengbianhao() {returnkechengbianhao;

}public voidsetKechengbianhao(String kechengbianhao) {this.kechengbianhao =kechengbianhao;

}publicString getJiaoshixingming() {returnjiaoshixingming;

}public voidsetJiaoshixingming(String jiaoshixingming) {this.jiaoshixingming =jiaoshixingming;

}publicString getXuehao() {returnxuehao;

}public voidsetXuehao(String xuehao) {this.xuehao =xuehao;

}publicString getXingming() {returnxingming;

}public voidsetXingming(String xingming) {this.xingming =xingming;

}

}

packageStudent;public classKechengService {staticString kechengbianhao;staticString kechengmingcheng;staticString renkejiaoshi;static intxianyourenshu;static intrenshushangxian;public static intgetRenshushangxian() {returnrenshushangxian;

}public static void setRenshushangxian(intrenshushangxian) {

KechengService.renshushangxian=renshushangxian;

}public staticString getKechengbianhao() {returnkechengbianhao;

}public static voidsetKechengbianhao(String kechengbianhao) {

KechengService.kechengbianhao=kechengbianhao;

}public staticString getKechengmingcheng() {returnkechengmingcheng;

}public static voidsetKechengmingcheng(String kechengmingcheng) {

KechengService.kechengmingcheng=kechengmingcheng;

}public staticString getRenkejiaoshi() {returnrenkejiaoshi;

}public static voidsetRenkejiaoshi(String renkejiaoshi) {

KechengService.renkejiaoshi=renkejiaoshi;

}public static intgetXianyourenshu() {returnxianyourenshu;

}public static void setXianyourenshu(intxianyourenshu) {

KechengService.xianyourenshu=xianyourenshu;

}

}

packageStudent;importjava.io.IOException;importjava.util.List;importjavax.servlet.ServletException;importjavax.servlet.annotation.WebServlet;importjavax.servlet.http.HttpServlet;importjavax.servlet.http.HttpServletRequest;importjavax.servlet.http.HttpServletResponse;importLogin.Power;importTeacher.KechengService;/*** Servlet implementation class LLKEServlet*/@WebServlet("/LLKCServlet")public class LLKCServlet extendsHttpServlet {private static final long serialVersionUID = 1L;/***@seeHttpServlet#HttpServlet()*/

publicLLKCServlet() {super();//TODO Auto-generated constructor stub

}protected void service(HttpServletRequest arg0, HttpServletResponse arg1) throwsServletException, IOException

{

arg0.setCharacterEncoding("utf-8");

arg1.setCharacterEncoding("utf-8");booleanflag;

String function=arg0.getParameter("method");if(function.equals("submit"))

{

List userall =Get.getAll0();

java.util.Collections.reverse(userall);

arg0.setAttribute("all", userall);

arg0.getRequestDispatcher("student/liulan.jsp").forward(arg0, arg1);

}if(function.equals("kecheng"))

{

String kechengbianhao=arg0.getParameter("kechengbianhao");

Find f=newFind();

f.findclass("class", kechengbianhao);

arg0.getRequestDispatcher("student/kecheng.jsp").forward(arg0, arg1);

}if(function.equals("jiaoshi"))

{

String gonghao;

gonghao=arg0.getParameter("gonghao");

Find f=newFind();

f.findjiaoshi("teacher", gonghao);

arg0.getRequestDispatcher("student/jiaoshi.jsp").forward(arg0, arg1);

}

}/***@seeHttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)*/

protected void doGet(HttpServletRequest request, HttpServletResponse response) throwsServletException, IOException {//TODO Auto-generated method stub

response.getWriter().append("Served at: ").append(request.getContextPath());

}/***@seeHttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)*/

protected void doPost(HttpServletRequest request, HttpServletResponse response) throwsServletException, IOException {//TODO Auto-generated method stub

doGet(request, response);

}

}

packageStudent;importjava.sql.Connection;importjava.sql.ResultSet;importjava.sql.SQLException;importjava.sql.Statement;importLogin.DBUtil;public classSelect {public booleanselect(String table,String kechengbianhao,String xuehao)

{boolean c=true;

Connection conn=DBUtil.getConn();

Statement state=null;try{

state=conn.createStatement();

String sql="select * from "+table;

ResultSet rs=state.executeQuery(sql);while(rs.next())

{if(kechengbianhao.equals(rs.getString(1))&&xuehao.equals(rs.getString(4)))

{

c=false;

}

}

rs.close();

state.close();

conn.close();

}catch(Exception e)

{

}returnc;

}

}

packageStudent;public classService {staticString xuehao;staticString xingming;staticString xingbie;staticString banji;staticString zhuanye;public staticString getXuehao() {returnxuehao;

}public static voidsetXuehao(String xuehao) {

Service.xuehao=xuehao;

}public staticString getXingming() {returnxingming;

}public static voidsetXingming(String xingming) {

Service.xingming=xingming;

}public staticString getXingbie() {returnxingbie;

}public static voidsetXingbie(String xingbie) {

Service.xingbie=xingbie;

}public staticString getBanji() {returnbanji;

}public static voidsetBanji(String banji) {

Service.banji=banji;

}public staticString getZhuanye() {returnzhuanye;

}public static voidsetZhuanye(String zhuanye) {

Service.zhuanye=zhuanye;

}

}

packageStudent;importjava.io.IOException;importjavax.servlet.ServletException;importjavax.servlet.annotation.WebServlet;importjavax.servlet.http.HttpServlet;importjavax.servlet.http.HttpServletRequest;importjavax.servlet.http.HttpServletResponse;importLogin.Power;/*** Servlet implementation class SXiugaiServlet*/@WebServlet("/SXiugaiServlet")public class SXiugaiServlet extendsHttpServlet {private static final long serialVersionUID = 1L;/***@seeHttpServlet#HttpServlet()*/

publicSXiugaiServlet() {super();//TODO Auto-generated constructor stub

}protected void service(HttpServletRequest arg0, HttpServletResponse arg1) throwsServletException, IOException

{

arg0.setCharacterEncoding("utf-8");

arg1.setCharacterEncoding("utf-8");booleanflag;

String function=arg0.getParameter("method");if(function.equals("submit"))

{

Find f=newFind();

f.find("student", Power.getXingming());

arg0.getRequestDispatcher("student/xiugaixinxi.jsp").forward(arg0, arg1);

}if(function.equals("xiugai"))

{

Change c=newChange();

String xingming;

xingming=arg0.getParameter("xingming");

String xingbie;

xingbie=arg0.getParameter("xingbie");

String banji;

banji=arg0.getParameter("banji");

String zhuanye;

zhuanye=arg0.getParameter("zhuanye");

c.change("jieguo", "xingming", "xuehao", xingming, Service.getXuehao());

c.change("login", "name", "username", xingming, Power.getUsername());

Power.setUsername(xingming);

c.change("student", "xingming", "xuehao", xingming, Service.getXuehao());

c.change("student", "xingbie", "xuehao", xingbie, Service.getXuehao());

c.change("student", "xueyuan", "xuehao", banji, Service.getXuehao());

c.change("student", "zhicheng", "xuehao", zhuanye, Service.getXuehao());

arg0.setAttribute("message", "修改成功");

arg0.getRequestDispatcher("Right.jsp").forward(arg0, arg1);

}

}/***@seeHttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)*/

protected void doGet(HttpServletRequest request, HttpServletResponse response) throwsServletException, IOException {//TODO Auto-generated method stub

response.getWriter().append("Served at: ").append(request.getContextPath());

}/***@seeHttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)*/

protected void doPost(HttpServletRequest request, HttpServletResponse response) throwsServletException, IOException {//TODO Auto-generated method stub

doGet(request, response);

}

}

packageStudent;public classTeacherService {staticString gonghao;staticString xingming;staticString xingbie;staticString xueyuan;staticString zhicheng;public staticString getGonghao() {returngonghao;

}public static voidsetGonghao(String gonghao) {

TeacherService.gonghao=gonghao;

}public staticString getXingming() {returnxingming;

}public static voidsetXingming(String xingming) {

TeacherService.xingming=xingming;

}public staticString getXingbie() {returnxingbie;

}public static voidsetXingbie(String xingbie) {

TeacherService.xingbie=xingbie;

}public staticString getXueyuan() {returnxueyuan;

}public static voidsetXueyuan(String xueyuan) {

TeacherService.xueyuan=xueyuan;

}public staticString getZhicheng() {returnzhicheng;

}public static voidsetZhicheng(String zhicheng) {

TeacherService.zhicheng=zhicheng;

}

}

packageStudent;importjava.io.IOException;importjava.util.List;importjavax.servlet.ServletException;importjavax.servlet.annotation.WebServlet;importjavax.servlet.http.HttpServlet;importjavax.servlet.http.HttpServletRequest;importjavax.servlet.http.HttpServletResponse;importLogin.Power;importTeacher.KechengService;/*** Servlet implementation class XuankeServlet*/@WebServlet("/XuankeServlet")public class XuankeServlet extendsHttpServlet {private static final long serialVersionUID = 1L;/***@seeHttpServlet#HttpServlet()*/

publicXuankeServlet() {super();//TODO Auto-generated constructor stub

}protected void service(HttpServletRequest arg0, HttpServletResponse arg1) throwsServletException, IOException

{

arg0.setCharacterEncoding("utf-8");

arg1.setCharacterEncoding("utf-8");booleanflag;

String function=arg0.getParameter("method");if(function.equals("submit"))

{

List userall =Get.getAll();

java.util.Collections.reverse(userall);

arg0.setAttribute("all", userall);

arg0.getRequestDispatcher("student/xuanke.jsp").forward(arg0, arg1);

}if(function.equals("xuanke"))

{

Change c=newChange();

Jieguo j=newJieguo();

Find f=newFind();

f.find("student", Power.getXingming());

String jiaoshixingming;

jiaoshixingming=arg0.getParameter("jiaoshixingming");

j.setJiaoshixingming(jiaoshixingming);

String kechengbianhao;

kechengbianhao=arg0.getParameter("kechengbianhao");

j.setKechengbianhao(kechengbianhao);

String xianyourenshu;

xianyourenshu=arg0.getParameter("xianyourenshu");

String gonghao;

gonghao=arg0.getParameter("gonghao");

j.setGonghao(gonghao);

j.setXingming(Service.getXingming());

j.setXuehao(Service.getXuehao());int num=Integer.parseInt(xianyourenshu);

num++;

System.out.println(num);

Select s=newSelect();

flag=s.select("jieguo",kechengbianhao,Service.getXuehao());if(flag)

{

c.change("class", "xianyourenshu", "kechengbianhao", num+"", kechengbianhao);

Add a=newAdd();

a.add("jieguo", j);

arg0.setAttribute("message", "选课成功");

arg0.getRequestDispatcher("Right.jsp").forward(arg0, arg1);

}else{

arg0.setAttribute("message", "选课重复");

arg0.getRequestDispatcher("Right.jsp").forward(arg0, arg1);

}

}

}/***@seeHttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)*/

protected void doGet(HttpServletRequest request, HttpServletResponse response) throwsServletException, IOException {//TODO Auto-generated method stub

response.getWriter().append("Served at: ").append(request.getContextPath());

}/***@seeHttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)*/

protected void doPost(HttpServletRequest request, HttpServletResponse response) throwsServletException, IOException {//TODO Auto-generated method stub

doGet(request, response);

}

}

Teacher包中的文件:

packageTeacher;importjava.sql.Connection;importjava.sql.SQLException;importjava.sql.Statement;importLogin.DBUtil;public classAdd {public booleanadd(String table,KechengService en)

{boolean c=false;

String sql="insert into "+table+"(kechengbianhao,kechengmingcheng,gonghao,renkejiaoshi,renshushangxian,xianyourenshu) values('"+en.getKechengbianhao()+"','"+en.getKechengmingcheng()+"','"+en.getGonghao()+"','"+en.getRenkejiaoshi()+"','"+en.getRenshushangxian()+"','"+en.getXianyourenshu()+"');";

Connection conn=DBUtil.getConn();

Statement state=null;try{

state=conn.createStatement();int num=state.executeUpdate(sql);if(num!=0)

c=true;

state.close();

conn.close();

}catch(SQLException e) {//TODO Auto-generated catch block//e.printStackTrace();

}returnc;

}

}

packageTeacher;importjava.sql.Connection;importjava.sql.SQLException;importjava.sql.Statement;importLogin.DBUtil;public classChange {public booleanchange(String table,String lie,String lie0,String gai,String biao)

{

Connection conn=DBUtil.getConn();

Statement state=null;try{

state=conn.createStatement();

String sql="update "+table+" set "+lie+"='"+gai+"' where "+lie0+"='"+biao+"'";

System.out.println(sql);

state.executeUpdate(sql);

state.close();

conn.close();

}catch(SQLException e) {//TODO Auto-generated catch block

e.printStackTrace();

}return true;

}

}

packageTeacher;importjava.sql.Connection;importjava.sql.ResultSet;importjava.sql.Statement;importLogin.DBUtil;public classFind {public booleanfind(String table,String id)

{booleanc;

Connection conn=DBUtil.getConn();

Statement state=null;try{

state=conn.createStatement();

String sql="select * from "+table+" where xingming ='"+id+"'";

ResultSet rs=state.executeQuery(sql);while(rs.next())

{

Service.setGonghao(rs.getString(1));

Service.setXingming(rs.getString(2));

Service.setXingbie(rs.getString(3));

Service.setXueyuan(rs.getString(4));

Service.setZhicheng(rs.getString(5));

}

rs.close();

state.close();

conn.close();

System.out.println("over");

}catch(Exception e)

{

}return true;

}

}

packageTeacher;importjava.sql.Connection;importjava.sql.PreparedStatement;importjava.sql.ResultSet;importjava.util.ArrayList;importjava.util.List;importLogin.DBUtil;public classGet {public static ListgetAll(String id)

{

List list=new ArrayList();

Connection conn=DBUtil.getConn();

PreparedStatement state=null;

ResultSet rs=null;

String sql="select * from class where gonghao ='"+id+"'";try{

state=conn.prepareStatement(sql);

rs=state.executeQuery();while(rs.next())

{

KechengService user=newKechengService();

user.setKechengbianhao(rs.getString(1));

user.setKechengmingcheng(rs.getString(2));

user.setGonghao(rs.getString(3));

user.setRenkejiaoshi(rs.getString(4));

user.setXianyourenshu(rs.getInt(6));

list.add(user);

}

rs.close();

state.close();

conn.close();

}catch(Exception e)

{

}if(list!=null) {returnlist;

}else{return null;

}

}public static ListgetAllxs(String bianhao)

{

List list=new ArrayList();

Connection conn=DBUtil.getConn();

PreparedStatement state=null;

ResultSet rs=null;

String sql="select * from jieguo";try{

state=conn.prepareStatement(sql);

rs=state.executeQuery();while(rs.next())

{if(rs.getString(1).equals(bianhao))

{

Xuesheng user=newXuesheng();

user.setXingming(rs.getString(4));

user.setXuehao(rs.getString(3));

list.add(user);

}

}

rs.close();

state.close();

conn.close();

}catch(Exception e)

{

}if(list!=null) {returnlist;

}else{return null;

}

}

}

packageTeacher;public classKechengService {

String kechengbianhao;

String kechengmingcheng;

String renkejiaoshi;intrenshushangxian;intxianyourenshu;

String gonghao;publicString getGonghao() {returngonghao;

}public voidsetGonghao(String gonghao) {this.gonghao =gonghao;

}publicString getKechengbianhao() {returnkechengbianhao;

}public voidsetKechengbianhao(String kechengbianhao) {this.kechengbianhao =kechengbianhao;

}publicString getKechengmingcheng() {returnkechengmingcheng;

}public voidsetKechengmingcheng(String kechengmingcheng) {this.kechengmingcheng =kechengmingcheng;

}publicString getRenkejiaoshi() {returnrenkejiaoshi;

}public voidsetRenkejiaoshi(String renkejiaoshi) {this.renkejiaoshi =renkejiaoshi;

}public intgetRenshushangxian() {returnrenshushangxian;

}public void setRenshushangxian(intrenshushangxian) {this.renshushangxian =renshushangxian;

}public intgetXianyourenshu() {returnxianyourenshu;

}public void setXianyourenshu(intxianyourenshu) {this.xianyourenshu =xianyourenshu;

}

}

packageTeacher;importjava.io.IOException;importjavax.servlet.ServletException;importjavax.servlet.annotation.WebServlet;importjavax.servlet.http.HttpServlet;importjavax.servlet.http.HttpServletRequest;importjavax.servlet.http.HttpServletResponse;importLogin.Power;importLogin.Select;/*** Servlet implementation class KechengServlet*/@WebServlet("/KechengServlet")public class KechengServlet extendsHttpServlet {private static final long serialVersionUID = 1L;/***@seeHttpServlet#HttpServlet()*/

publicKechengServlet() {super();//TODO Auto-generated constructor stub

}protected void service(HttpServletRequest arg0, HttpServletResponse arg1) throwsServletException, IOException

{

Select s=newSelect();

arg0.setCharacterEncoding("utf-8");

arg1.setCharacterEncoding("utf-8");booleanflag;

String function=arg0.getParameter("method");if(function.equals("submit"))

{

Find f=newFind();

f.find("teacher", Power.getXingming());

Add a=newAdd();

KechengService ks=newKechengService();

String kechengbianhao;

kechengbianhao=arg0.getParameter("kechengbianhao");

ks.setKechengbianhao(kechengbianhao);

String kechengmingcheng;

kechengmingcheng=arg0.getParameter("kechengmingcheng");

ks.setKechengmingcheng(kechengmingcheng);

String renkejiaoshi;

renkejiaoshi=Power.getXingming();

String gonghao;

gonghao=Service.getGonghao();

ks.setGonghao(gonghao);

ks.setRenkejiaoshi(renkejiaoshi);

String renshushangxian;

renshushangxian=arg0.getParameter("renshushangxian");int num=Integer.parseInt(renshushangxian);

ks.setRenshushangxian(num);

ks.setXianyourenshu(0);

a.add("class", ks);

arg0.setAttribute("message", "添加成功");

arg0.getRequestDispatcher("teacher/tianjiakecheng.jsp").forward(arg0, arg1);

}

}/***@seeHttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)*/

protected void doGet(HttpServletRequest request, HttpServletResponse response) throwsServletException, IOException {//TODO Auto-generated method stub

response.getWriter().append("Served at: ").append(request.getContextPath());

}/***@seeHttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)*/

protected void doPost(HttpServletRequest request, HttpServletResponse response) throwsServletException, IOException {//TODO Auto-generated method stub

doGet(request, response);

}

}

packageTeacher;importjava.io.IOException;importjava.util.List;importjavax.servlet.ServletException;importjavax.servlet.annotation.WebServlet;importjavax.servlet.http.HttpServlet;importjavax.servlet.http.HttpServletRequest;importjavax.servlet.http.HttpServletResponse;importLogin.Power;importLogin.Select;/*** Servlet implementation class LiulanServlet*/@WebServlet("/LiulanServlet")public class LiulanServlet extendsHttpServlet {private static final long serialVersionUID = 1L;/***@seeHttpServlet#HttpServlet()*/

publicLiulanServlet() {super();//TODO Auto-generated constructor stub

}/***@seeHttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)*/

protected void doGet(HttpServletRequest request, HttpServletResponse response) throwsServletException, IOException {//TODO Auto-generated method stub

response.getWriter().append("Served at: ").append(request.getContextPath());

}protected void service(HttpServletRequest arg0, HttpServletResponse arg1) throwsServletException, IOException

{

Select s=newSelect();

arg0.setCharacterEncoding("utf-8");

arg1.setCharacterEncoding("utf-8");booleanflag;

String function=arg0.getParameter("method");if(function.equals("liulan"))

{

List userall =Get.getAll(Service.getGonghao());

java.util.Collections.reverse(userall);

arg0.setAttribute("all", userall);

arg0.getRequestDispatcher("teacher/liulanxuanke.jsp").forward(arg0, arg1);

}if(function.equals("xiangxi"))

{

String kechengbianhao;

kechengbianhao=arg0.getParameter("kechengbianhao");

List userall =Get.getAllxs(kechengbianhao);

java.util.Collections.reverse(userall);

arg0.setAttribute("all", userall);

arg0.getRequestDispatcher("teacher/xiangxi.jsp").forward(arg0, arg1);

}

}/***@seeHttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)*/

protected void doPost(HttpServletRequest request, HttpServletResponse response) throwsServletException, IOException {//TODO Auto-generated method stub

doGet(request, response);

}

}

packageTeacher;public classService {staticString gonghao;staticString xingming;staticString xingbie;staticString xueyuan;public staticString getGonghao() {returngonghao;

}public static voidsetGonghao(String gonghao) {

Service.gonghao=gonghao;

}public staticString getXingming() {returnxingming;

}public static voidsetXingming(String xingming) {

Service.xingming=xingming;

}public staticString getXingbie() {returnxingbie;

}public static voidsetXingbie(String xingbie) {

Service.xingbie=xingbie;

}public staticString getXueyuan() {returnxueyuan;

}public static voidsetXueyuan(String xueyuan) {

Service.xueyuan=xueyuan;

}public staticString getZhicheng() {returnzhicheng;

}public static voidsetZhicheng(String zhicheng) {

Service.zhicheng=zhicheng;

}staticString zhicheng;

}

packageTeacher;importjava.io.IOException;importjavax.servlet.ServletException;importjavax.servlet.annotation.WebServlet;importjavax.servlet.http.HttpServlet;importjavax.servlet.http.HttpServletRequest;importjavax.servlet.http.HttpServletResponse;importLogin.Power;/*** Servlet implementation class TXiugaiServlet*/@WebServlet("/TXiugaiServlet")public class TXiugaiServlet extendsHttpServlet {private static final long serialVersionUID = 1L;/***@seeHttpServlet#HttpServlet()*/

publicTXiugaiServlet() {super();//TODO Auto-generated constructor stub

}protected void service(HttpServletRequest arg0, HttpServletResponse arg1) throwsServletException, IOException

{

arg0.setCharacterEncoding("utf-8");

arg1.setCharacterEncoding("utf-8");booleanflag;

String function=arg0.getParameter("method");if(function.equals("submit"))

{

Find f=newFind();

f.find("teacher", Power.getXingming());

arg0.getRequestDispatcher("teacher/xiugaixinxi.jsp").forward(arg0, arg1);

}if(function.equals("xiugai"))

{

Change c=newChange();

String xingming;

xingming=arg0.getParameter("xingming");

String xingbie;

xingbie=arg0.getParameter("xingbie");

String xueyuan;

xueyuan=arg0.getParameter("xueyuan");

String zhicheng;

zhicheng=arg0.getParameter("zhicheng");

c.change("class", "renkejiaoshi", "gonghao", xingming, Service.getGonghao());

c.change("login", "name", "username", xingming, Power.getUsername());

Power.setUsername(xingming);

c.change("teacher", "xingming", "gonghao", xingming, Service.getGonghao());

c.change("teacher", "xingbie", "gonghao", xingbie, Service.getGonghao());

c.change("teacher", "xueyuan", "gonghao", xueyuan, Service.getGonghao());

c.change("teacher", "zhicheng", "gonghao", zhicheng, Service.getGonghao());

arg0.setAttribute("message", "修改成功");

arg0.getRequestDispatcher("Right.jsp").forward(arg0, arg1);

}

}/***@seeHttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)*/

protected void doGet(HttpServletRequest request, HttpServletResponse response) throwsServletException, IOException {//TODO Auto-generated method stub

response.getWriter().append("Served at: ").append(request.getContextPath());

}/***@seeHttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)*/

protected void doPost(HttpServletRequest request, HttpServletResponse response) throwsServletException, IOException {//TODO Auto-generated method stub

doGet(request, response);

}

}

packageTeacher;public classXuesheng {

String xingming;

String xuehao;publicString getXingming() {returnxingming;

}public voidsetXingming(String xingming) {this.xingming =xingming;

}publicString getXuehao() {returnxuehao;

}public voidsetXuehao(String xuehao) {this.xuehao =xuehao;

}

}

JSP文件中:

guanli文件夹:

Insert title here

//

//接收servlet传过来的那个message的参数//alert是js语句中的弹出警示框,也就是弹出message中的参数

Object message=request.getAttribute("message");if(!(message==null||message.equals("")))

{%>

账号
密码
工号:
姓名:
性别:
所在学院:
职称:
Insert title here

//

//接收servlet传过来的那个message的参数//alert是js语句中的弹出警示框,也就是弹出message中的参数

Object message=request.getAttribute("message");if(!(message==null||message.equals("")))

{%>

账号
密码
学号:
姓名:
性别:
班级:
专业:

student文件夹中:

Insert title here
工号:
任课教师
教师性别
学院:
职称
Insert title here
课程编号:
课程名称:
任课教师:
课程容量:
现有人数:
Insert title here
课程名称课程编号任课教师
${stu.getKechengmingcheng() }${stu.getKechengbianhao() }${stu.getRenkejiaoshi() }
Insert title here

//

//接收servlet传过来的那个message的参数//alert是js语句中的弹出警示框,也就是弹出message中的参数

Object message=request.getAttribute("message");if(!(message==null||message.equals("")))

{%>

学号
姓名>
性别>
班级>
专业>
Insert title here
课程名称课程编号任课教师操作
${stu.getKechengmingcheng() }${stu.getKechengbianhao() }${stu.getRenkejiaoshi() }选课

teacher文件中的:

Insert title here
课程名称课程编号现有人数
${stu.getKechengmingcheng()}${stu.getKechengbianhao() }${stu.getXianyourenshu() }
Insert title here

//

//接收servlet传过来的那个message的参数//alert是js语句中的弹出警示框,也就是弹出message中的参数

Object message=request.getAttribute("message");if(!(message==null||message.equals("")))

{%>

课程编号
课程名称
课程人数
Insert title here
姓名学号
${stu.getXingming() }${stu.getXuehao() }
Insert title here

//

//接收servlet传过来的那个message的参数//alert是js语句中的弹出警示框,也就是弹出message中的参数

Object message=request.getAttribute("message");if(!(message==null||message.equals("")))

{%>

工号
姓名>
性别>
所在学院>
职称>

最下面的JSP文件:

Insert title here

//

//接收servlet传过来的那个message的参数//alert是js语句中的弹出警示框,也就是弹出message中的参数

Object message=request.getAttribute("message");if(!(message==null||message.equals("")))

{%>

Insert title here

margin:0;

padding:0;

font-size: 12px;

font-family: "Microsoft Yahei", Verdana, Arial, Helvetica, sans-serif

}

.leftMenu {

min-width:220px;

width:268px;

margin:40px auto0auto;

}

.menu {

border: #bdd7f2 1px solid;

border-top: #0080c4 4px solid;

border-bottom: #0080c4 4px solid;

background: #f4f9ff repeat-y right;

margin-left: 10px;

}

.menu .ListTitle {

border-bottom: 1px #98c9ee solid;

display: block;

text-align: center;/*position: relative;*/height: 38px;

line-height: 38px;

cursor: pointer;/*+min-width:220px;*/

+width:100%;

}

.ListTitlePanel {

position: relative;

}

.leftbgbt {

position: absolute;

background: no-repeat;

width: 11px;

height: 52px;

left:-11px;

top:-4px;

}/*.leftbgbt {

float:left;

background: no-repeat;

width: 11px;

height: 52px;

left: 0px;

top: 0px;

zoom:1;

z-index:200px;

}*/.leftbgbt2 {

position: absolute;

background: no-repeat;

width: 11px;

height: 48px;

left:-11px;

top:-1px;

}

.menuList {

display: block;

height: auto;

}

.menuList div {

height: 28px;

line-height: 24px;

border-bottom: 1px #98c9ee dotted;

}

.menuList div a {

display: block;

background: #fff;

line-height: 28px;

height: 28px;

color: #185697;

text-decoration: none;

}

.menuList div a:hover {

color: #f30;

background: #0080c4;

color: #fff;

}

//

//接收servlet传过来的那个message的参数//alert是js语句中的弹出警示框,也就是弹出message中的参数

int message=Power.getFlag();%>

>

登录

//

//接收servlet传过来的那个message的参数//alert是js语句中的弹出警示框,也就是弹出message中的参数

Object message=request.getAttribute("message");if(!(message==null||message.equals("")))

{%>

账号:
密码:
身份:

管理员

教师

学生

Insert title here

//

//接收servlet传过来的那个message的参数//alert是js语句中的弹出警示框,也就是弹出message中的参数

Object message=request.getAttribute("message");if(!(message==null||message.equals("")))

{%>

Insert title here

流转系统

首 页     退出

以上的代码均按顺序发出。

现在发一些运行图:

af6f7f65ef91d59a4f2e6902052f1ac7.png

管理员:

5399d76e34be8477aadd9be6a5402a55.png

学生:

abde3494638767710bb945a830fcb371.png

375fd0fbd5f17cc6875280b286364d56.png

932ddeb9ccacd5cb52dcd63023576517.png

教师:

d7b543c4aa61eb2de0f40054bbc0306d.png

4ae28fdce072a558bc98877aaf3fea19.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值