该系统管理员可以添加和删除学生、教师,教师可以修改自己信息、添加课程、浏览自己课程,学生可以修改自己的信息、选课、浏览全部课程。
首先展示文件:
然后就是一次展示代码:
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("")))
{%>
账号 | |
密码 | |
工号: | |
姓名: | |
性别: | |
所在学院: | |
职称: |
//
//接收servlet传过来的那个message的参数//alert是js语句中的弹出警示框,也就是弹出message中的参数
Object message=request.getAttribute("message");if(!(message==null||message.equals("")))
{%>
账号 | |
密码 | |
学号: | |
姓名: | |
性别: | |
班级: | |
专业: |
student文件夹中:
Insert title here工号: | |
任课教师 | |
教师性别 | |
学院: | |
职称 |
课程编号: | |
课程名称: | |
任课教师: | |
课程容量: | |
现有人数: |
课程名称 | 课程编号 | 任课教师 |
${stu.getKechengmingcheng() } | ${stu.getKechengbianhao() } | ${stu.getRenkejiaoshi() } |
//
//接收servlet传过来的那个message的参数//alert是js语句中的弹出警示框,也就是弹出message中的参数
Object message=request.getAttribute("message");if(!(message==null||message.equals("")))
{%>
学号 | |
姓名 | > |
性别 | > |
班级 | > |
专业 | > |
课程名称 | 课程编号 | 任课教师 | 操作 |
${stu.getKechengmingcheng() } | ${stu.getKechengbianhao() } | ${stu.getRenkejiaoshi() } | 选课 |
teacher文件中的:
Insert title here课程名称 | 课程编号 | 现有人数 |
${stu.getKechengmingcheng()} | ${stu.getKechengbianhao() } | ${stu.getXianyourenshu() } |
//
//接收servlet传过来的那个message的参数//alert是js语句中的弹出警示框,也就是弹出message中的参数
Object message=request.getAttribute("message");if(!(message==null||message.equals("")))
{%>
课程编号 | |
课程名称 | |
课程人数 |
姓名 | 学号 |
${stu.getXingming() } | ${stu.getXuehao() } |
//
//接收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 heremargin: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("")))
{%>
账号: | |
密码: | |
身份: | 管理员 教师 学生 |
//
//接收servlet传过来的那个message的参数//alert是js语句中的弹出警示框,也就是弹出message中的参数
Object message=request.getAttribute("message");if(!(message==null||message.equals("")))
{%>
Insert title here流转系统
以上的代码均按顺序发出。
现在发一些运行图:
管理员:
学生:
教师: