选课管理系统

在课上的时候完成了管理员登陆界面、管理界面和简单的学生与教师登录界面。(后续完成)

下面是原题:

石家庄铁道大学选课管理系统

1、项目需求:

本项目所开发的学生选课系统完成学校对学生的选课信息的统计与管理,减少数据漏掉的情况,同时也节约人力、物力和财力。告别以往的人工统计。

2.系统要求与功能设计

2.1 页面要求

1)能够在Tomcat服务器中正确部署,并通过浏览器查看;

2)网站页面整体风格统一;

3)首页(登录页)要求实现不同用户登录后,进入的功能页不相同。

4)教师功能页:有添加课程、修改个人信息、浏览选课学生信息三个模块。

5)学生功能页:有修改个人信息、浏览课程信息、选课三个功能模块。

5)管理员功能页:有添加教师信息、添加学生信息两个模块。

2.2功能要求:

1)添加教师信息:管理员可以添加教师基本信息,教师基本信息包括:教师工号(八位数字组成,例如02000081)、教师姓名、教师性别、教师所在学院、职称(教授、副教授、讲师、助教)组成;

2)添加学生信息:管理可以添加学生基本信息,学生基本信息包括学号(八位数字组成,例如20180052)、学生姓名、学生性别、所在班级、所属专业组成;

3)添加课程信息:教师登陆后,可以添加自己任职的课程基本信息,课程基本信息包括:课程编号(六位数字组成,例如050013),课程名称、选课人数、任课教师(任课教师不需录入,那位教师填写课程信息,那位教师就是任课教师);

4)修改个人信息:教师或学生登陆后可以修改个人信息,但教师工号或学号不能修改,另外教师或学生只能修改自己的信息,无法看到或修改其他学生或教师的基本信息。

5)浏览课程信息:学生登陆后可以看到所有课程的列表信息,点击课程名称可以查看课程的详细信息,包括已选课人数;点击教师名称可以查看教师的详细信息。

6)选课:进入选课页面,课程信息列表显示所有选课人数未达到课程设置的选课人数上限,点击课程名称可以看到课程详细信息,点击课程详细信息页面的“选课”按钮,可以实现选课功能。

7)浏览选课学生信息:教师进入该页面后,可以看到自己设置的课程信息列表,点击课程名称,可以看到,选择该课程的所有学生基本信息列表。

8)登陆功能:管理员、教师、学生登陆后可以看到不同的功能页面,教师或学生登陆后只能看到自己的相关信息,不同教师、不同学生登陆后无法查看其他人的信息。(要求至少创建两个教师用户、十个学生用户演示选课过程)

3数据库设计:

要求实现课程基本信息表、教师基本信息表、学生基本信息表、选课基本信息表。(提示:选课基本信息包括课程编号、教师编号、学号等基本信息)

4、WEB发布:

要求可以实现在浏览器直接访问系统。

 

评分等级分类:

 

A级:起评分90分,要求完全按照要求实现全部功能。(结合以前成绩综合考量,确认为免试);

 

B级:起评分80分,最高分不超过89分,可以完成选课的基本流程,实现教师、学生、课程基本信息添加、选课功能实现,剩余功能有两个以下(包括两个)未实现;

C级:起评分70分,最高分不超过79分,可以实现教师、学生、课程基本信息添加、修改个人信息,无法实现选课功能;

D级:起评分60分,最高分不超过69分,可以完成教师、学生、课程两个以上(包括两个)基本信息添加;

E级:无法达到上述级别要求。

 

以下是所建的表格(连接数据库、与数据库进行数据交互):

所有表格      管理员: 

学生:

 

老师:

 

 

 以下是包装的类:

 

连接数据库操作:

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * @author Hu
 *
 */
public class DBUtil {
    
    public static String db_url = "jdbc:mysql://localhost:3306/homework?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true";
    public static String db_user = "root";
    public static String db_pass = "101032";
    
    public static Connection getConn () {
        Connection conn = null;
        
        
        try {
            //加载驱动
            Class.forName("com.mysql.jdbc.Driver");
            //获取连接
            conn = DriverManager.getConnection(db_url, db_user, db_pass);
            System.out.println("连接成功!");
            
        } catch (Exception e) {
            e.printStackTrace();
        }
        
        return conn;
    }
    public static void main(String[] args) {
        getConn();
    }
    
    /**
     * @param state
     * @param conn
     */
    public static void close (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 void close (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();
            }
        }
    }

}

管理员Bean:

public class users {
private String name;
private String password;
public String getName() {
    return name;
}
public void setName(String name) {
    this.name = name;
}
public String getPassword() {
    return password;
}
public void setPassword(String password) {
    this.password = password;
}

}

 学生Bean:

public class user {
    
    private String id;
    private String name;
    private String password;
    private String realname;
    private String sex;
    private String number;
    private String adress;
    

    
    public void setId(String id) {
        this.id = id;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getPassword() {
        return password;
    }
    public void setPassword(String password) {
        this.password = password;
    }
    public String getRealname() {
        return realname;
    }
    public void setRealname(String realname) {
        this.realname = realname;
    }
    public String getSex() {
        return sex;
    }
    public void setSex(String sex) {
        this.sex = sex;
    }
    public String getnumber() {
        return number;
    }
    public void setnumber(String number) {
        this.number = number;
    }
    
    public String getAdress() {
        return adress;
    }
    public void setAdress(String adress) {
        this.adress = adress;
    }
    public String getId() {
        return id;
    }
    
}

老师Bean:

public class tuser {
    private String id;
    private String name;
    private String password;
    private String realname;
    private String sex;
    private String number;
    private String adress;
    

    
    public void setId(String id) {
        this.id = id;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getPassword() {
        return password;
    }
    public void setPassword(String password) {
        this.password = password;
    }
    public String getRealname() {
        return realname;
    }
    public void setRealname(String realname) {
        this.realname = realname;
    }
    public String getSex() {
        return sex;
    }
    public void setSex(String sex) {
        this.sex = sex;
    }
    public String getnumber() {
        return number;
    }
    public void setnumber(String number) {
        this.number = number;
    }
    
    public String getAdress() {
        return adress;
    }
    public void setAdress(String adress) {
        this.adress = adress;
    }
    public String getId() {
        return id;
    }
    
}

管理员Dao:(学生和老师的Dao类似)

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.SQLException;

import com.util.DBUtil;

public class dengluDao {

    
    public static String searchUsername(String name) {
        String sql="select * from admin where ";
        if(name!=null) {
            sql=sql+"name like+'%"+name+"%'";
        }
        Connection conn=DBUtil.getConn();
        Statement state=null; 
        ResultSet rs=null;
        String name1=null;
        try {
        state=conn.createStatement();
        rs=state.executeQuery(sql);
        while(rs.next())
        {
            name1=rs.getString("name");
            
        }
        } catch (Exception e) {
            e.printStackTrace();
        }finally{
            DBUtil.close(rs,state, conn);
        }
        return name1;
        
    }
    public static String searchPassword(String name) {
        String sql="select * from admin where ";
        if(name!=null) {
            sql=sql+"name like '%"+name+"%'";
        }
        Connection conn=DBUtil.getConn();
        Statement state=null;
        ResultSet rs=null;
        String password1=null;
        try {
        state=conn.createStatement();
        rs=state.executeQuery(sql);
        while(rs.next()) {
            password1=rs.getString("password");
        }
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            DBUtil.close(rs,state,conn);
        }
        return password1;
    }
}

删除:

import java.sql.Connection;
import java.sql.SQLException;

import com.mysql.jdbc.PreparedStatement;
import com.util.DBUtil;

public class DeleteDao {
    
    Connection conn = DBUtil.getConn(); //连接数据库
    public boolean delete(String username) {
        boolean flag=false;
        try {
            String sql="delete from homework where name='"+username+"'";
            PreparedStatement pstmt = (PreparedStatement) conn.prepareStatement(sql);
            int i = pstmt.executeUpdate();
            pstmt.close();
            conn.close();
            if(i>0) flag = true;
        }catch(SQLException e) {
            System.out.println("删除失败");    
            e.printStackTrace();
        }

        return flag;

        }
}

添加学生:

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;

import com.domain.user;
import com.util.DBUtil;

public class RegisterDao {

    /**
     * 用户注册
     * @param user
     * @return
     */
    public boolean register(user user) {
        /*`id` int(11) NOT NULL AUTO_INCREMENT,
          `name` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
          `password` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
          `realname` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
          `sex` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
          `area` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
          `phone` varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
          `email` varchar(50)*/
        String sql = "insert into homework(name,password,realname,sex,number,adress) values(?,?,?,?,?,?)";
        Connection conn = DBUtil.getConn(); //连接数据库
        PreparedStatement pstmt = null;
        int count = 0;
        try {
            pstmt = conn.prepareStatement(sql);//用于将 SQL 语句发送到数据库中。
            pstmt.setString(1,user.getName());//1代表第一列
            pstmt.setString(2,user.getPassword());
            pstmt.setString(3,user.getRealname());
            pstmt.setString(4,user.getSex());
            
            pstmt.setString(5,user.getnumber());
            pstmt.setString(6,user.getAdress());
            count = pstmt.executeUpdate();//返回的是受影响的行数(即更新的行数)
        } catch (SQLException e) {
            // TODO 自动生成的 catch 块
            e.printStackTrace();
        }
        if(count>0) {
            return true;
        }
        return false;
    }

}

显示:

import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import com.domain.user;
import com.mysql.jdbc.PreparedStatement;
import com.mysql.jdbc.ResultSet;
import com.mysql.jdbc.Statement;
import com.util.DBUtil;

public class ShowDao {
    public List<user> select(){
        Connection conn = DBUtil.getConn(); //连接数据库
        List<user> list = new ArrayList<user>();
        try {
            String sql="select * from homework";
            Statement pstmt = (Statement) conn.createStatement();
            ResultSet rs = (ResultSet) pstmt.executeQuery(sql);
            while(rs.next()) {
                user user=new user();
                user.setId("id");
                user.setName(rs.getString("name"));
                user.setPassword(rs.getString("password"));
                user.setRealname(rs.getString("realname"));
                user.setSex(rs.getString("sex"));
                user.setnumber(rs.getString("number"));
                user.setAdress(rs.getString("adress"));
                list.add(user);
            }
            System.out.println("hhh");
            rs.close();
            pstmt.close();
            conn.close();

        }catch(SQLException e) {
            e.printStackTrace();
        }
        return list;
    }
}

更新:

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import com.util.DBUtil;

public class UpdateDao {
    //Connection conn = DBUtil.getConn(); //连接数据库
    public boolean update(String name, String password,String realname, String sex,String number,String adress) {
        boolean flag = false;
        String sql="update homework set sex ='"+sex
                +"' where password='"+password+"'";
        Connection conn = DBUtil.getConn(); //连接数据库
        try {
            PreparedStatement ps =conn.prepareStatement(sql);
            int i =  ps.executeUpdate();
            System.out.println("1111");
            if(i>0) flag = true;
            System.out.println(flag);
            System.out.println(i);
            ps.close();
            conn.close();
        } catch (SQLException e) {
            // TODO: handle exception
            System.out.println("更新失败");
            e.printStackTrace();
        }
        
        return flag;
        
    }
}

Service层:

import com.dao.RegisterDao;
import com.domain.user;

public class RegisterService {

    private RegisterDao dao = new RegisterDao();
    
    /**
     * 用于用户注册
     * @param user
     * @return
     */
    public boolean register(user user) {
        boolean registerSuccess = false;
        
        registerSuccess = dao.register(user);//判断是否存入数据库成功
        
        return registerSuccess;
    }

}

 

import java.util.List;

import com.dao.ShowDao;
import com.domain.user;

public class ShowService {
private ShowDao sd=new ShowDao();
public List<user> list() {
    return sd.select();
}
}

Servlet层:

登录(管理员)

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.dao.dengluDao;
/**
 * Servlet implementation class IndexServlet
 */
@WebServlet("/IndexServlet")
public class dengluServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public dengluServlet() {
        super();
        // TODO Auto-generated constructor stub
    }
    dengluDao dao=new dengluDao();
    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        String name=request.getParameter("name");
        String password=request.getParameter("password");
        String rname=dao.searchUsername(name);
        String rpassword=dao.searchPassword(name);
        if(name.equals(rname)&&password.equals(rpassword)) {
            request.getRequestDispatcher("index.jsp").forward(request, response);
            System.out.println("IndexServlet跳转成功");
        }
        else {
            request.getRequestDispatcher("denglu.jsp").forward(request,response);
            System.out.println("IndexServlet跳转失败");
            System.out.println(name+password);
            System.out.println(rname+rpassword);
        }
    }

    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        request.setCharacterEncoding("UTF-8");
        String method=request.getParameter("method");
        if("search".equals(method))
        {
            doGet(request, response);
        }
        
    }

}

删除(学生)

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.dao.DeleteDao;
import com.domain.user;
import com.util.DBUtil;

/**
 * Servlet implementation class DeleteServlet
 */
public class DeleteServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public DeleteServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        
        String name = request.getParameter("name");
        String password=request.getParameter("password");
        /*String classteacher=request.getParameter("classteacher");
        String classplace=request.getParameter("classplace");*/
        user user = new user();
        user.setName(name);
        user.setPassword(password);
        /*school.setclassteacher(classteacher);
        school.setclassplace(classplace);
        */
        //查找要删除的用户和密码
        //String sql = "SELECT * FROM homework WHERE name='"+name+"' AND password='"+password+"'";
        Connection conn = DBUtil.getConn();
        Statement state = null;
        ResultSet rs = null;
        
        DeleteDao sd = new DeleteDao();
        try {
            state = conn.createStatement();
            //rs = state.executeQuery(sql);//executeQuery()返回包含给定查询所生成数据的 ResultSet 对象,如果没有查询到信息,返回一个next()为false的ResultSet 对象
            //if(rs.next()) {
            sd.delete(name);
            response.setCharacterEncoding("gbk");
            PrintWriter out = response.getWriter();
            out.println("<script> alert('删除成功'); window.location.href='ShowServlet'; </script>");
            //response.sendRedirect(request.getContextPath() + "/delete.jsp");
            //}
            //else {response.setCharacterEncoding("gbk");
            //PrintWriter out = response.getWriter();
            //out.println("<script> alert('删除失败,用户不存在或输入有误'); window.location.href='delete.jsp'; </script>");}
        }catch(Exception e) {
            System.out.println("删除失败");
            e.printStackTrace();
        }
    }

    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        doGet(request, response);
    }

}

添加(学生)

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.domain.user;
import com.service.RegisterService;
import com.util.DBUtil;

/**
 * Servlet implementation class RegisterServlet
 */
public class RegisterServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;
    private RegisterService Ser = new RegisterService();
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public RegisterServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        String name = request.getParameter("name");     //getParameter()获取的是客户端设置的数据。
        String password = request.getParameter("password");
        String realname = request.getParameter("realname");
        String sex = request.getParameter("sex");
        String number = request.getParameter("number");
        String adress = request.getParameter("adress");
        //String Strsql="select name from homework where name=? ";
        //String[] params= {name};
        
        String sql = "select name from homework where ";
        if (name != "") {
            sql += "name like '%" + name + "%'";
        }

        Connection conn = DBUtil.getConn();
        Statement state = null;
        ResultSet rs = null;
        try {
            state = conn.createStatement();
            rs = state.executeQuery(sql);//executeQuery()返回包含给定查询所生成数据的 ResultSet 对象,如果没有查询到信息,返回一个next()为false的ResultSet 对象
            if(rs.next()==false) {
                //name = rs.getString("name");

                user user = new user();
                user.setName(name);
                user.setPassword(password);
                user.setRealname(realname);
                user.setSex(sex);
                user.setnumber(number);

                user.setAdress(adress);
                response.setCharacterEncoding("gbk");
                PrintWriter out = response.getWriter();
                System.out.println(" "+user.getName()+" "+user.getPassword()+" "+user.getRealname()+" "+user.getSex()+" "+user.getnumber());
                if(Ser.register(user)) {
                    out.println("<script> alert('添加成功!'); window.location.href='ShowServlet'; </script>");
                    
                }else {
                    out.println("<script> alert('添加失败!'); window.location.href='register.jsp'; </script>");
                }
                out.println("</HTML>");
                out.flush();     //out.flush()表示强制将缓冲区中的数据发送出去,不必等到缓冲区满
                out.close();     
                
            }
            else {response.setCharacterEncoding("gbk");
                PrintWriter out = response.getWriter();
                out.println("<script> alert('该用户已存在,添加失败!'); window.location.href='register.jsp'; </script>");
                out.println("</HTML>");
                out.flush();     //out.flush()表示强制将缓冲区中的数据发送出去,不必等到缓冲区满
                out.close();     
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            DBUtil.close(rs, state, conn);
        }

    
        
        
    }
    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        doGet(request, response);
    }

}

显示(学生)

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.dao.ShowDao;
import com.domain.user;
import com.service.*;

/**
* Servlet implementation class ShowServlet
*/
public class ShowServlet extends HttpServlet {
private static final long serialVersionUID = 1L;

/**
* @see HttpServlet#HttpServlet()
*/
public ShowServlet() {
super();
// TODO Auto-generated constructor stub
}

/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
request.setCharacterEncoding("utf-8");
response.setContentType("text/html;charset=utf-8");

//String name = request.getParameter("name");
//String password = request.getParameter("password");
//String realname = request.getParameter("realname");
//String sex = request.getParameter("sex");
//String number = request.getParameter("number");
//String email = request.getParameter("email");
//ShowService ss=new ShowService();
//List<user> list = ss.list();

ShowDao sd = new ShowDao();
List<user> list = sd.select();
request.setAttribute("list", list);
System.out.println("hhhhh");
request.getRequestDispatcher("show.jsp").forward(request, response);
}

/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
}

}

更新(学生):

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.dao.UpdateDao;
import com.domain.*;
/**
 * Servlet implementation class UpdateServlet
 */
public class UpdateServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public UpdateServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        //String id1 = request.getParameter("id");
        
        //int id = Integer.parseInt((String)request.getParameter("id"));
        request.setCharacterEncoding("UTF-8");
        String name = request.getParameter("name");
        String password = request.getParameter("password");
        String realname = request.getParameter("realname");
        String sex = request.getParameter("sex");
        String number = request.getParameter("number");
        String adress = request.getParameter("adress");
        ///System.out.println("------------------------------------"+id);
        
        UpdateDao ud = new UpdateDao();
        try {
        if(ud.update(name, password, realname, sex, number,adress)){
            //request.setAttribute("xiaoxi", "更新成功");
            //request.getRequestDispatcher("/ShowServlet").forward(request, response);
            System.out.println("meiyou");
            request.getRequestDispatcher("/ShowServlet").forward(request, response);
            //request.getRequestDispatcher("/ShowServlet").forward(request, response);
            
        }
        else {PrintWriter out = response.getWriter();
        out.println("<script> alert('更新失败'); window.location.href='ShowServlet'; </script>");}
        
        }catch(Exception e){
            //response.sendRedirect("index.jsp");
            PrintWriter out = response.getWriter();
            out.println("<script> alert('更新失败'); window.location.href='ShowServlet'; </script>");
            e.printStackTrace();    
        }

    }

    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        doGet(request, response);
    }

}

jsp:

选课系统:

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>石家庄铁道大学选课管理系统</title>
</head>
<body>
<div align="center">
<h2>管理界面</h2>
<a href="denglu.jsp">管理员登陆</a>
<a href="denglu1.jsp">学生登陆</a>
<a href="denglu2.jsp">教师登陆</a>
</div>
</body>
</html>

登录界面:(管理员)

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>登录</title>
<!-- Bootstrapvalidate导入 -->
<link rel="stylesheet" href="${pageContext.request.contextPath }/plug-ins/css/bootstrapValidator.css" />
<link href="${pageContext.request.contextPath}/plug-ins/css/demo.css" rel="stylesheet" type="text/css">
<!-- Bootstrap -->
<link href="${pageContext.request.contextPath}/plug-ins/css/bootstrap.css" rel="stylesheet">

<!-- jQuery (Bootstrap 的所有 JavaScript 插件都依赖 jQuery,所以必须放在前边) -->
<script src="${pageContext.request.contextPath}/plug-ins/js/jquery-1.10.2.min.js"></script>

<!-- 加载 Bootstrap 的所有 JavaScript 插件。你也可以根据需要只加载单个插件。 -->
<script src="${pageContext.request.contextPath}/plug-ins/js/bootstrap.js"></script>
</head>
<body>
<div class="col-lg-8 col-lg-offset-2">
   <div class="page-header">
   <div style="background-color:rgb(255,255,0)">
   <h1 >管理员登录</h1>
   </div>
  <h2>登录</h2>
  <form action="${pageContext.request.contextPath }/dengluServlet?method=search" class="form-horizontal" role="form">
  <div class="form-group">
  <label class="col-lg-3 control-label">账号:</label>
  <div class="col-lg-8">
  <input type="text" class="form-control" name="name" placeholding="账号"/>
  </div>
  <label class="col-lg-3 control-label">密码:</label>
  <div class="col-lg-8">
  <input type="password" class="form-control" name="password" placeholding="密码"/>
  </div>
  <div>
  <button type="submit" class="btn bvtn-primary">登录</button>
  </div>
  </div>
  
  </form>
   </div>
</div>
</body>
</html>

管理员管理界面:

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>主界面</title>
</head>
<body>
<div align="center">
<h2>管理界面</h2>
<a href="register.jsp">学生添加</a>
<a href="register1.jsp">教师添加</a>
<a href="ShowServlet">查询学生信息</a>
<a href="ShowServlet1">查询教师信息</a>
<a href="xuankexitong.jsp">退出</a>
</div>
</body>
</html>

添加学生界面:

<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>用户添加</title>

<!-- Bootstrapvalidate导入 -->
<link rel="stylesheet" href="${pageContext.request.contextPath }/plug-ins/css/bootstrapValidator.css" />
<link href="${pageContext.request.contextPath}/plug-ins/css/demo.css" rel="stylesheet" type="text/css">
<!-- Bootstrap -->
<link href="${pageContext.request.contextPath}/plug-ins/css/bootstrap.css" rel="stylesheet">

<!-- jQuery (Bootstrap 的所有 JavaScript 插件都依赖 jQuery,所以必须放在前边) -->
<script src="${pageContext.request.contextPath}/plug-ins/js/jquery-1.10.2.min.js"></script>

<!-- 加载 Bootstrap 的所有 JavaScript 插件。你也可以根据需要只加载单个插件。 -->
<script src="${pageContext.request.contextPath}/plug-ins/js/bootstrap.js"></script>

<!-- validate表单验证导入 -->
<script type="text/javascript" src="${pageContext.request.contextPath}/plug-ins/js/bootstrapValidator.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/plug-ins/js/bootstrapValidator_zh_CN.js"></script>

<!-- Font Awesome -->
<link rel="stylesheet" href="${pageContext.request.contextPath}/plug-ins/css/font-awesome.min.css">

<script type="text/javascript">
    $(function() {
        //#''单引号里面是下面form标签的id
        $('#registe').bootstrapValidator(
                {
                    message : 'This value is not valid',
                    feedbackIcons : {
                        valid : 'glyphicon glyphicon-ok',
                        invalid : 'glyphicon glyphicon-remove',
                        validating : 'glyphicon glyphicon-refresh'
                    },
                    fields : {
                        name : {
                            validators : {
                                notEmpty : {
                                    message : '姓名不能为空'
                                },
                                stringLength : {
                                    min : 1,
                                    max : 12,
                                    message : '姓名由1-12个字符组成'
                                },
                                regexp : {
                                    regexp : /[\u4E00-\u9FA5]+$/,
                                    message : '姓名只能由中文组成'
                                }
                            }
                        },
                        password:{
                            validators:{
                                notEmpty : {
                                    message : '密码不能为空'
                                },
                                stringLength : {
                                    min : 1,
                                    max : 8,
                                    message : '密码必须由1-8个字母数字组成'
                                },
                                regexp : {
                                    regexp : /^[a-zA-Z0-9]+$/,
                                    message : '密码只能由字母数字组成'
                                }
                            }
                        },
                        realname:{
                            validators:{
                                notEmpty : {
                                    message : '所属班级不能为空'
                                }
                            }
                        },
                        number:{
                            validators:{
                                notEmpty : {
                                    message : '学号不能为空'
                                },
                                stringLength : {
                                    min : 1,
                                    max : 8,
                                    message : '学号必须由1-8位字符组成'
                                },
                                regexp : {
                                    regexp : /^2018(\d{4})+$/,
                                    message : '请输入正确的学号'
                                }
                            }
                        },
                    },
                });
    });
</script>

</head>
<body>
         <div class="col-lg-8 col-lg-offset-2">
             <div class="page-header">
                 <h2>信息登记</h2>
             </div>

             <form id="registe" method="post" class="form-horizontal" action="${pageContext.request.contextPath }/RegisterServlet">
                 <div class="form-group">
                     <label class="col-lg-3 control-label">姓名:</label>
                     <div class="col-lg-4">
                         <input type="text" class="form-control" name="name" placeholder="请输入姓名" />
                     </div>
                 </div>

                 <div class="form-group">
                     <label class="col-lg-3 control-label">密码:</label>
                     <div class="col-lg-5">
                         <input type="password" class="form-control" name="password" placeholder="请输入密码" />
                     </div>
                 </div>
                 
                  <div class="form-group">
                     <label class="col-lg-3 control-label">所属班级:</label>
                     <div class="col-lg-5">
                         <input type="text" class="form-control" name="realname" placeholder="请输入所属班级" />
                     </div>
                 </div>
                 
                  <div class="form-group">
                     <label class="col-lg-3 control-label">性别:</label>
                     <div class="col-lg-5">
                        <input type="radio" name="sex" value="man" checked="checked"/><input type="radio" name="sex" value="woman" /></div>
                 </div>

                 <div class="form-group">
                     <label class="col-lg-3 control-label">学号:</label>
                     <div class="col-lg-5">
                         <input type="text" class="form-control" name="number"  placeholder="请输入学号"/>
                     </div>
                 </div>
                 
                 <div class="form-group">
                     <label class="col-lg-3 control-label">所在学院:</label>
                     <div class="col-lg-5">
                         <input type="text" class="form-control" name="adress"  placeholder="请输入学院"/>
                     </div>
                 </div>

                 <div class="form-group">
                     <div class="col-lg-3 col-lg-offset-3">
                         <button type="submit" class="btn btn-primary">添加</button>
                 
             </form>
             
             <!--
             <div><a  href="delete.jsp"><font SIZE="4" >删除用户</font></a></div>
                    <div><a  href="ShowServlet"><font SIZE="4" >查看用户</font></a></div>
        -->
             <div><a  href="index.jsp"><font SIZE="4" >返回</font></a></div>
         </div>
</body>
</html>

显示学生:

<%@ page language="java"  import="java.util.*" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> 
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <base href="<%=basePath%>">
    <title>志愿者信息页面</title>
  </head>
  
  <body>
  <h1>${xiaoxi}</h1>
  <table  width="600" border="1" cellpadding="0" >
          <tr>
              <th>姓名</th>
              <th>密码</th>
              <th>所在班级</th>
              <th>性别</th>
              <th>学号</th>
              <th>所属学院</th>
              <th>操作:</th>
          </tr>
     <c:forEach var="U" items="${list}"  > 
      <form action="UpdateServlet" method="post"> 
       <tr>
           <td><input type="text" value="${U.name}" name="name"></td>
           <td><input type="text" value="${U.password}" name="password"></td>
           <td><input type="text" value="${U.realname}" name="realname"></td>
           <td><input type="text" value="${U.sex}" name="sex"></td>
           <td><input type="text" value="${U.number}" name="number"></td>
           <td><input type="text" value="${U.adress}" name="adress"></td>
           <td><a onclick="return check()" href="DeleteServlet?name=${U.name}">删除</a>  <input type="submit" value="更新"/></td>
       </tr>
    </form> 
    </c:forEach>
    <form id="registe" method="post" class="form-horizontal" action="${pageContext.request.contextPath }/Show1Servlet">  
    <tr>
    
    <td><input type="text" class="form-control" name="name" placeholder="请输入姓名"></td>
    <td><input type="text" class="form-control" name="realname" placeholder="请输入所属班级"></td>
    <td><input type="text" class="form-control" name="sex" placeholder="请输入性别"></td>
    <td><input type="text" class="form-control" name="number" placeholder="请输入学号"></td>
    </tr>
    <button type="submit" class="btn btn-primary">查询</button>
    </form>
    <div><a  href="index.jsp"><font SIZE="4" >返回</font></a></div>
    
    </table>
    <script type="text/javascript">
        function check() {
            if (confirm("是否确认删除该志愿者信息?")){
                return true;
            }else{
                return false;
            }
        }
    </script>
  </body>
</html>

以上的是今天下午完成的,其余的功能后续完成。

posted @ 2019-12-16 21:01  ziyuliu  阅读(2662)  评论(2编辑  收藏  举报