Background of the project
Student information management is one of the important tasks of the school. Because traditional student information management is manual, the workload is heavy and error-prone. With the rapid development of computer and network technology, more and more institutions have their own student information management systems, and it is a trend to use B/S architecture student information management systems to manage student information.
The foundation of Java web technology is the core Java platform, which has many advantages, such as the "write once, run anywhere" feature, JDBC API technology that facilitates database access,
and the security model that can protect data in Internet applications, etc. The J2EE architecture provides a middle-tier integration framework to meet application requirements for high availability, high reliability, and scalability, and provides a good mechanism for building network application systems with scalability, flexibility, and ease of maintenance.
This paper designs and implements a simplified version of the student information management system based on Java web platform technology and using the Browser/Server structure.
The paper first introduces the relevant technologies and development platforms involved in system development, mainly focusing on the relevant technologies and system architecture implemented by the student information management system, and introduces the overall analysis and design of the student information management system, including demand analysis, functional module analysis and Database Design. Finally, a simple student information management subsystem is implemented using the Jsp+Servlet+JavaBean model and described in detail. The implementation of the system functions is described in detail mainly by combining pictures and code.
Keywords: Student information management system, Java web, Servlet, JSP
feature design
Function module diagram
System structure chart
User login flow chart
Program flow chart
Function screenshot
Related code
1public class LoginServlet extends HttpServlet {
2 private static final long serialVersionUID = 1L;
3 protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
4 request.setCharacterEncoding("utf-8");
5 String username = request.getParameter("username");
6 String password = request.getParameter("password");
7 String level = null;
8 //实例化UserDao对象
9 UserDao userDao = new UserDao();
10 User user = userDao.login(username, password);
11 //判断是否登录成功
12 if(user != null){
//成功
13 level = user.getLevel();
14 if(level.equals("用户")){
15 request.getSession().setAttribute("user", user);//将用户对象放到session中
16 //转发到user.jsp中
17 request.getRequestDispatcher("user.jsp").forward(request, response);
18 }
19 else{
20 request.getSession().setAttribute("admin", user);//将管理员对象放到session中
21 //转发到admin.jsp中
22 request.getRequestDispatcher("admin.jsp").forward(request, response);
23 }
24 }else {
//失败
25 request.setAttribute("info"," 错误:用户名或密码错误!");
26 request.getRequestDispatcher("message.jsp").forward(request, response);
27 }
28 }
}
1public class CourseDao {
2 // 获取所有课程的信息,用ArrayList返回
3 public ArrayList<Course> query_all_course() {
4 Connection conn = DBUtils.getConnection();
5 String sql = "select * from course order by cno;";
6 ArrayList<Course> results = new ArrayList<Course>();
7 try {
8 PreparedStatement ps = (PreparedStatement) conn.prepareStatement(sql);
9 ResultSet rs = ps.executeQuery();
10 while (rs.next()) {
11 Course temp = new Course();
12 temp.setCno(rs.getString("Cno"));
13 temp.setCname(rs.getString("Cname"));
14 temp.setCteacher(rs.getString("Cteacher"));
15 temp.setCcredit(rs.getInt("Ccredit"));
16 results.add(temp);
17 }
18 // 关闭资源
19 rs.close();
20 ps.close();
21 } catch (SQLException e) {
22 e.printStackTrace();
23 } finally {
24 DBUtils.closeConnection(conn);
25 }
26 return results;
27 }
28 // 插入课程信息,返回一个int值表示状态,1:成功,0失败
29 public int insert_course(String Cno, String Cname, String Cteacher, double Ccredit) {
30 Connection conn = DBUtils.getConnection();
31 String sql = "insert into course values(?,?,?,?);";
32 int flag = 0;
33 try {
34 PreparedStatement ps = (PreparedStatement) conn.prepareStatement(sql);
35 ps.setString(1, Cno);
36 ps.setString(2, Cname);
37 ps.setString(3, Cteacher);
38 ps.setDouble(4, Ccredit);
39 flag = ps.executeUpdate();
40 ps.close();
41 } catch (SQLException e) {
42 e.printStackTrace();
43 } finally {
44 DBUtils.closeConnection(conn);
45 }
46 return flag;
47 }
48 // 删除课程信息,返回一个int值表示状态,1:成功,0失败
49 public int delete_course(String Cno) {
50 Connection conn = DBUtils.getConnection();
51 String sql = "delete from course where Cno = ?;";
52 int flag = 0;
53 try {
54 PreparedStatement ps = (PreparedStatement) conn.prepareStatement(sql);
55 ps.setString(1, Cno);
56 flag = ps.executeUpdate();
57 ps.close();
58 } catch (SQLException e) {
59 e.printStackTrace();
60 } finally {
61 DBUtils.closeConnection(conn);
62 }
63 return flag;
64 }
65 //修改课程信息,返回一个int值表示状态,1:成功,0失败
66 public int alter_course(String cno,String after_cno,String after_cname,String after_cteacher,double after_ccredit) {
67 Connection conn = DBUtils.getConnection();
68 String sql = "update course set cno = ?,cname = ?,cteacher = ?,ccredit = ? where cno = ?;";
69 int flag = 0;
70 try {
71 PreparedStatement ps = (PreparedStatement) conn.prepareStatement(sql);
72 ps.setString(1, after_cno);
73 ps.setString(2, after_cname);
74 ps.setString(3, after_cteacher);
75 ps.setDouble(4, after_ccredit);
76 ps.setString(5, cno);
77 flag = ps.executeUpdate();
78 ps.close();
79 } catch (SQLException e) {
80 e.printStackTrace();
81 }finally {
82 DBUtils.closeConnection(conn);
83 }
84 return flag;
85 }
86 // 查询课程平均分信息,返回一个ArrayLst集合
87 public ArrayList<Course_avg> course_avg() {
88 Connection conn = DBUtils.getConnection();
89 String sql = "select sc.cno cno,cname,avg(grade) avg from course,sc where course.cno = sc.cno group by cno order by cno;";
90 ResultSet result = null;
91 ArrayList<Course_avg> course_avg = new ArrayList<Course_avg>();
92 try {
93 PreparedStatement ps = (PreparedStatement) conn.prepareStatement(sql);
94 result = ps.executeQuery();
95 while(result.next()){
96 Course_avg temp = new Course_avg();
97 temp.setCno(result.getString("Cno"));
98 temp.setCname(result.getString("Cname"));
99 temp.setAvg(result.getDouble("avg"));
100 course_avg.add(temp);
101 }
102 ps.close();
103 result.close();
104 } catch (SQLException e) {
105 e.printStackTrace();
106 } finally {
107 DBUtils.closeConnection(conn);
108 }
109 return course_avg;
110 }
111 //查询课程不及格率,返回一个ArrayList集合
112 public ArrayList<Course_fail_rate> fail_rate(){
113 Connection conn = DBUtils.getConnection();
114 String sql = "select cno,(select cname from course where cno = x.cno) cname,cast(100.0*(select count(sno) from sc where grade < 60 and cno = x.cno)/(select count(sno) from sc where cno = x.cno) as decimal(18,2)) rate from sc x group by cno order by cno;";
115 ArrayList<Course_fail_rate> fail_rate = new ArrayList<Course_fail_rate>();
116 try {
117 PreparedStatement ps = (PreparedStatement) conn.prepareStatement(sql);
118 ResultSet rs = ps.executeQuery();
119 while(rs.next()){
120 Course_fail_rate temp = new Course_fail_rate();
121 temp.setCno(rs.getString("cno"));
122 temp.setCname(rs.getString("cname"));
123 temp.setFail_rate(rs.getDouble("rate"));
124 fail_rate.add(temp);
125 }
126 rs.close();
127 ps.close();
128 } catch (SQLException e) {
129 e.printStackTrace();
130 } finally {
131 DBUtils.closeConnection(conn);
132 }
133 return fail_rate;
134 }
135 //查询课程排名情况,返回一个ArrayList集合
136 public ArrayList<Course_ranking> course_ranking(String cno){
137 Connection conn = DBUtils.getConnection();
138 String sql = "select student.Sno Sno,Dname,Clname,Sname,Ssex,Sage,Grade from department,class,student,sc where student.sno = sc.sno and class.Clno = student.Clno and department.Dno = class.Dno and cno = '"+cno+"' order by grade desc;";
139 ArrayList<Course_ranking> course_ranking = new ArrayList<Course_ranking>();
140 try {
141 PreparedStatement ps = (PreparedStatement) conn.prepareStatement(sql);
142 ResultSet rs = ps.executeQuery();
143 while(rs.next()){
144 Course_ranking temp = new Course_ranking();
145 temp.setSno(rs.getString("Sno"));
146 temp.setDname(rs.getString("Dname"));
147 temp.setClname(rs.getString("Clname"));
148 temp.setSname(rs.getString("Sname"));
149 temp.setSsex(rs.getString("Ssex"));
150 temp.setSage(rs.getInt("Sage"));
151 temp.setGrade(rs.getDouble("Grade"));
152 course_ranking.add(temp);
153 }
154 rs.close();
155 ps.close();
156 } catch (SQLException e) {
157 e.printStackTrace();
158 } finally {
159 DBUtils.closeConnection(conn);
160 }
161 return course_ranking;
162 }
}