JavaWeb学生管理系统

一、功能展示

1.登陆页面

   

2.添加学生

JavaWeb学生管理系统_第1张图片

3.添加成绩

JavaWeb学生管理系统_第2张图片

4.查询成绩

JavaWeb学生管理系统_第3张图片

5.成绩柱状图

JavaWeb学生管理系统_第4张图片

6.修改删除学生信息

JavaWeb学生管理系统_第5张图片

7.成绩报表

JavaWeb学生管理系统_第6张图片

8.导出成绩报表

JavaWeb学生管理系统_第7张图片

二、功能设计

学生成绩管理功能

  1. 添加学生功能:姓名、学号、性别、出生年月日。(学号自动生成且唯一)
  2. 添加学生成绩功能:每个人都有数学、Java、英语、体育四门课,可分课程输入成绩。
  3. 根据学生学号查找学生成绩功能:在界面上显示姓名、学号和成绩,学号不存在的能给出提示信息。
  4. 根据学生姓名(支持模糊匹配)查找学生成绩功能:并在界面上显示姓名、学号和成绩,如果有多个相同姓名学生存在,一起显示出来,姓名不存在的给出提示信息。
  5. 支持对单个学生各科成绩画出柱状分布图。
  6. 学生信息的修改与删除功能:不能修改学号。
  7. 生成学生学习情况报表功能:报表包含学号、姓名、各科目成绩及对应的该科目班级平均值,总成绩以及班级总成绩平均值,并将该排序结果输出至excel文件

功能

JSP+JavaBean+Servlet

三、功能实现

数据库设计

JavaWeb学生管理系统_第8张图片

设计三个表一个学生信息表information

JavaWeb学生管理系统_第9张图片

管理员登陆表

JavaWeb学生管理系统_第10张图片

学生成绩表

JavaWeb学生管理系统_第11张图片

项目表

JavaWeb学生管理系统_第12张图片

JavaWeb学生管理系统_第13张图片

web.xml(进行Severlet的部署)



  ManSystem
  
  
    This is the description of my J2EE component
    This is the display name of my J2EE component
    NumberQueryScoreServlet
    jdbc.NumberQueryScoreServlet
  
  
    This is the description of my J2EE component
    This is the display name of my J2EE component
    NameQueryScoreServlet
    jdbc.NameQueryScoreServlet
  
  
    This is the description of my J2EE component
    This is the display name of my J2EE component
    UpdateInformationServlet
    jdbc.UpdateInformationServlet
  
  
    This is the description of my J2EE component
    This is the display name of my J2EE component
    UpdateChangeInformationServlet
    jdbc.UpdateChangeInformationServlet
  
  
    This is the description of my J2EE component
    This is the display name of my J2EE component
    BarChartServlet
    jdbc.BarChartServlet
  
  
    This is the description of my J2EE component
    This is the display name of my J2EE component
    FormServlet
    jdbc.FormServlet
  






  
    NumberQueryScoreServlet
    /NumberQueryScoreServlet
  
  
    NameQueryScoreServlet
    /NameQueryScoreServlet
  
  
    UpdateInformationServlet
    /UpdateInformationServlet
  
  
    UpdateChangeInformationServlet
    /UpdateChangeInformationServlet
  
  
    BarChartServlet
    /BarChartServlet
  
  
    FormServlet
    /FormServlet
  
  
  
  
  
  
  
    index.html
    index.htm
    index.jsp
    default.html
    default.htm
    default.jsp
  

 

学生类StudentBean.java(用来存放学生的信息)

package jdbc;
import java.sql.Date;
public class StudentBean {
	private int number = 0;
	private String name=null;
	private String sex=null;
	private String birth=null;
	private int math=0;
	private int java=0;
	private int english=0;
	private int pe=0;
	private int avg=0;
	
	public StudentBean() {}
	public StudentBean(int number,String name,int math,int java,int english,int pe,int avg) {
		this.number=number;
		this.name=name;
		this.math=math;
		this.java=java;
		this.english=english;
		this.pe=pe;
		this.avg=avg;
	}
	public int getnumber() {return this.number;}
	public String getname() {return this.name;}
	public String getsex() {return this.sex;}
	public String getbirth() {return this.birth;}
	public int getmath() {return this.math;}
	public int getjava() {return this.java;}
	public int getenglish() {return this.english;}
	public int getpe() {return this.pe;}
	public int getavg() {return this.avg;}
	
	public void setnumber(int number) {this.number=number;}
	public void setname(String name) {this.name=name;}
	public void setsex(String sex) {this.sex=sex;}
	public void setbirth(String birth) {this.birth=birth;}
	public void setmath(int math) {this.math=math;}
	public void setjava(int java) {this.java=java;}
	public void setenglish(int english) {this.english=english;}
	public void setpe(int pe) {this.pe=pe;}
	public void setavg(int avg) {this.avg=avg;}

}

wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw==

数据库类MysqlBean.java(用来进行数据库连接或者进行数据库操作)

package jdbc;
import java.sql.*;
import java.util.ArrayList;
import java.util.List;

public class MysqlBean 
{
	private String drv = "com.mysql.jdbc.Driver";//数据库驱动程序
	private String url = "jdbc:mysql://localhost:3306/student";//主机的URL
	private String usr = "root";//用户名
	private String pwd = "huang136";//口令
	private Connection conn = null;//数据库的连接对象
	private Statement stm = null;//SQL语句的声明对象
	private ResultSet rs = null;//结果集对象

//为以上定义的7个变量编写getter/setter方法
    public String getDrv() {
		return drv;
	}
	public void setDrv(String drv) {
		this.drv = drv;
	}
    public String getUrl() {
		return url;
	}
	public void setUrl(String url) {
		this.url = url;
	}
    public String getUsr() {
		return usr;
	}
	public void setUsr(String usr) {
		this.usr = usr;
	}
    public String getPwd() {
		return pwd;
	}
	public void setPwd(String pwd) {
		this.pwd = pwd;
	}
    public Connection getConn() {
		return conn;
	}
	public void setConn(Connection conn) {
		this.conn = conn;
	}
    public Statement getStm() {
		return stm;
	}
	public void setStm(Statement stm) {
		this.stm = stm;
	}
	public ResultSet getRs() {
		return rs;
	}
	public void setRs(ResultSet rs) {
		this.rs = rs;
	}
	
	public boolean createConn() {//创建数据库连接
		boolean b = false;
		try { 
			Class.forName(drv);
			conn = DriverManager.getConnection(url, usr, pwd);
			b = true;
		} catch (SQLException e) {
		} catch (ClassNotFoundException e) {
		} 
		return b;
	}

	public boolean update(String sql) {//更新数据库内容的SQL方法
		boolean b = false;
		try {	
			stm = conn.createStatement();
			stm.execute(sql);
			b = true;
		} catch (Exception e) {System.out.println(e.toString());  }
		return b;
	}
	
	public void query(String sql) {  //查询数据库内容的SQL方法
		try {	
			stm = conn.createStatement();
			rs = stm.executeQuery(sql);
		} catch (Exception e) {	}
	}

	public boolean next() {//移到下条记录的方法
		boolean b = false;
		try { 	
			if(rs.next())  
			b = true;
		} catch (Exception e) {	}
		return b;		
	}

	public String getValueString(String field) {//取得当前记录的字段field的值
		String value = null;
		try {
			if(rs!=null)
				value = rs.getString(field);
			} catch (Exception e) {	}
		return value;
	}
	public int getValueInt(String field) {//取得当前记录的字段field的值
		int value = 0;
		try {
			if(rs!=null)
				value = rs.getInt(field);
			} catch (Exception e) {	}
		return value;
	}
	public Date getValueDate(String field) {//取得当前记录的字段field的值
		Date value = null;
		try {
			if(rs!=null)
				value = rs.getDate(field);
			} catch (Exception e) {	}
		return value;
	}
	
	
	
	
	
	
	public List getValueScore(int number) {//取得当前记录的字段field的值
		List studentbeanlist=new ArrayList();
		try {
			String sql="select * from score where number like '%"+number+"%'";	
			stm = conn.createStatement();
			rs = stm.executeQuery(sql);
			while(rs.next())
			{
				StudentBean studentbean=new StudentBean();
				
				System.out.println(rs.getString("name"));
				
				studentbean.setnumber(rs.getInt("number"));
				studentbean.setname(rs.getString("name"));
				studentbean.setmath(rs.getInt("math"));
				studentbean.setjava(rs.getInt("java"));
				studentbean.setenglish(rs.getInt("math"));
				studentbean.setpe(rs.getInt("pe"));
				studentbeanlist.add(studentbean);
			}
		} catch (Exception e) {	}
		return studentbeanlist;
	}
	public List getNameScore(String name) {//取得当前记录的字段field的值
		List studentbeanlist=new ArrayList();
		try {
			String sql="select * from score where name like '%"+name+"%'";	
			stm = conn.createStatement();
			rs = stm.executeQuery(sql);
			while(rs.next())
			{
				StudentBean studentbean=new StudentBean();
				
				System.out.println(rs.getString("name"));
				
				studentbean.setnumber(rs.getInt("number"));
				studentbean.setname(rs.getString("name"));
				studentbean.setmath(rs.getInt("math"));
				studentbean.setjava(rs.getInt("java"));
				studentbean.setenglish(rs.getInt("math"));
				studentbean.setpe(rs.getInt("pe"));
				studentbeanlist.add(studentbean);
			}
		} catch (Exception e) {	}
		return studentbeanlist;
	}
	

//关闭与数据库连接相关的三个对象
	public void closeConn() { 
		try {	if (conn != null)	conn.close();
		} catch (SQLException e) {	}
	}

	public void closeStm() {
		try {	if (stm != null)	stm.close();
		} catch (SQLException e) {	}
	}

	public void closeRs() {
		try {	if (rs != null)	    rs.close();
		} catch (SQLException e) {}
	}
}

wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw==

登陆界面设计

登陆界面 login.jsp

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>




学生成绩管理系统





	

欢迎登录学生成绩管理系统

账号

密码

学生 管理员

wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw==

login.css

@charset "UTF-8";

body{
	background:url(/ManSystem/img/3.jpg) no-repeat;
	background-size:100% 100%;
	width:100%;
	height:100%;  
}
.title{
	width:100%;
	height:auto;
	background:#003b90;
	font-size:30px;
	text-align:center;
}
.title p{
	color: #fff;
}
body{
	background-color: white;
	text-algin:center;
}

#index{
	text-align:center;
	background-color:;
	margin:200px 0 0 41%;	
	width: 400px;
    height: 260px;
    padding: 13px;
    position: absolute;
    left: 50%;
    top: 50%;
    margin-left: -200px;
    margin-top: -300px;
    background-color: rgba(240, 255, 255, 0.5); 
    border-radius: 10px;
}
#btn_login {	
    font-size: 20px;
    width: 120px;
    height: 28px;
    line-height: 28px;
    text-align: center;
    color: white;
    background-color: #003b90;
    border-radius: 6px;
    border: 0;
}

wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw==

login_controller.jsp

<%@ page import="jdbc.LoginBean" %>
<%@ page import="jdbc.MysqlBean" %>
<%
	String userid=request.getParameter("userid");
	String password=request.getParameter("password");
	
	if(userid==""||password==""){
		response.sendRedirect("../view/login.jsp");
	}else{
		LoginBean loginbean=new LoginBean();
		boolean isvalid = loginbean.valid(userid,password);
		out.print(isvalid);

		if(isvalid){
			session.setAttribute("userid",userid);
			response.sendRedirect("../view/menu.jsp");
		}else{
			response.sendRedirect("../view/login.jsp");			
		}
	}
 %>

wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw==

LoginBean.java

package jdbc;
import java.sql.*;

public class LoginBean {
	public boolean valid(String userid,String password){
		boolean isvalid =false;
		MysqlBean db =new MysqlBean();
		if(db.createConn()) {
			String sql="select * from login where userid='"+userid+"'and password='"+password+"'";
			db.query(sql);
			if(db.next()){
				isvalid=true;
				}
				db.closeRs();
				db.closeStm();
				db.closeConn();
			}
		return isvalid;	
	}
}

wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw==

3.成绩报表
form.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>




成绩报表





	

成绩报表

学 号 姓 名 性 别 出 生 MATH JAVA ENGLISH PE 平均分
${U.number} ${U.name} ${U.sex} ${U.birth} ${U.math} ${U.java} ${U.english} ${U.pe} ${U.avg}
平 均 分 ${avg_math} ${avg_java} ${avg_english} ${avg_pe} ${avg_all}

form.css

@charset "UTF-8";

body{
	background:url(/ManSystem/img/3.jpg) no-repeat;
	background-size:100% 100%;
	width:100%;
	height:100%;  
}
.container{
	
	
	background-color: rgba(240, 255, 255, 0.5); 
    border-radius: 10px;
    width: 700px;
    height: auto;
 
}
#backViewTable{
		border-spacing: 0;
}

FormServlet.java

package jdbc;

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

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

public class FormServlet extends HttpServlet {

	/**
		 * Constructor of the object.
		 */
	public FormServlet() {
		super();
	}

	/**
		 * Destruction of the servlet. 
*/ public void destroy() { super.destroy(); // Just puts "destroy" string in log // Put your code here } /** * The doGet method of the servlet.
* * This method is called when a form has its tag value method equals to get. * * @param request the request send by the client to the server * @param response the response send by the server to the client * @throws ServletException if an error occurred * @throws IOException if an error occurred */ public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println(""); out.println(""); out.println(" A Servlet"); out.println(" "); out.print(" This is "); out.print(this.getClass()); out.println(", using the GET method"); out.println(" "); out.println(""); out.flush(); out.close(); } /** * The doPost method of the servlet.
* * This method is called when a form has its tag value method equals to post. * * @param request the request send by the client to the server * @param response the response send by the server to the client * @throws ServletException if an error occurred * @throws IOException if an error occurred */ public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { FormBean form=new FormBean(); List studentbeanlist=new ArrayList(); studentbeanlist = form.getForm(); if(studentbeanlist!=null){ request.getSession().setAttribute("studentbeanlist", studentbeanlist); request.getSession().setAttribute("avg_math", form.getavg_math()); request.getSession().setAttribute("avg_java", form.getavg_java()); request.getSession().setAttribute("avg_english", form.getavg_english()); request.getSession().setAttribute("avg_pe", form.getavg_pe()); request.getSession().setAttribute("avg_all", form.getavg_all()); RequestDispatcher view = request.getRequestDispatcher("view/form.jsp"); view.forward(request, response); }else{ RequestDispatcher view = request.getRequestDispatcher("/view/menu.jsp"); view.forward(request, response); } } /** * Initialization of the servlet.
* * @throws ServletException if an error occurs */ public void init() throws ServletException { // Put your code here } }

四、源代码

https://github.com/MarineKings/JavaWeb/tree/master/ManSystem

你可能感兴趣的:(JavaWeb)