学生成绩管理系统

基于Jsp+sql server数据库的学生成绩管理系统



需求分析

学生成绩管理系统需求服务对象为在校学生和在校交工
校教工. 整体分为学生模块和教师模块.

学生模块 需求 :
1:学生个体通过学号登录系统.

2:网页页面显示学生信息(学号,姓名,成绩,年龄,新版)
性别,联系方式,居住地)
3:学生个体可以修改自己的信息(姓名,性别,年龄,)
龄,联系方式,居住地)
4:学生无删除与增加自身信息的权限.
教师模块需求:

1:教师个体通过教工号登陆系统.
2:教师选择课程后查看所带班全部学生全部信息
3:教师登陆后允许修改学生成绩
4:教师可增加学生个体信息到系统表中
5:教师无删除学生个体信息权限

                                                                        项目构思

设计学生信息表,包含字段如下:

(学号,课程号,姓名,成绩,年龄,性别,联系方式,居住地)

住地)

设计教工表,包含字段如下:

(课程号,教工号,课程名,教工姓名,职称)

Register.jsp提供学生教师登录入口

registerForward.jsp判断用户身份

studentDispose.jsp显示学生信息

studentModification.jsp修改学生信息

teacherClass.jsp查找教师所带课程

Showinfo.jsp显示教师所带班级 学生信息

modificationScore.jsp显示要修改的学生成绩

finallyScoreModification.jsp修改成绩

addStudentInfo.jsp增添学生用户界面

finallAddinfo.jsp添加学生成绩

                                                                        详细设计

学生信息表:

(s# , c# ,sname , score,age,sex,telephone,home)

教工表:

(c#,cname,title,t#,tname)

Register.jsp功能:

分设两个入口:教师入口和学生入口

教师入口由教师工号字段进入

学生 入口由学生学号字段进入

RegisterForward.jsp功能:

接收由register.html提交的字段,并依submitvalue值判断提交按钮,并依此刷新到不同界面

studentDispose.jap功能:(registerForward.jsp

跳转)

链接数据库学生信息表,查询字段等于s#的元组,

将其显示在网页上,并设有修改按钮(提交至stud

entModification.jsp),查询后关闭数据库

studentModification.jsp功能:

接收由studentDispose.jsp传入的元组所有字段,

链接数据库,查询到对应s#,修改学生信息表属性

,显示修改成功或失败,返回登录入口.

teacherClass.jsp功能:

为教师提供课程选择功能.

链接数据库教工表,查询t#等于字段的所有c#,

页面显示教工的tname,title,并设有下拉列表框,

显示cname,设进入按钮,跳转页面并提交cname

字段.关闭数据库.

ShowInfo.jsp功能:

接收cname字段.链接数据库教工表,cname

段匹配c#,查询学生信息表,匹配c#字段,页面显

示对应行记录,标头显示tname,title,cname,行信

息右侧显示设修改超链接(超链接传入s#)

底部设有增加学生信息超链接.

Modification.jsp功能:

接收S#字段,链接数据库学生信息表,读取匹配s

#的字段行,页面显示s#,sname,score,设有修改按

.关闭数据库.

finallyScoreModification.jsp功能:

接收由modificationscore.jsp传入的s#,score.

链接数据库学生信息表,匹配s#,更新score,页面

显示修改成功或失败.

addStudentInfo.html功能:

学生信息填入表单(接收cname,showinfo提交)

用以录入学生信息,设提交按钮.

finallAddInfo.jsp功能:

接收addStudentInfo.html的字段.

链接数据库教工表,cname查询c#.

将接收的字段与c#作为记录插入到学生信息表

,显示插入成功或失败.

关闭数据库.5秒后跳转到showInfo页面.




代码部分:

register.jsp

<%@ page  pageEncoding="UTF-8" %>

登录入口



工号:

registerForward.js

function teacherCheck()
{
	
	if(document.form1.jobNumber.value=='')
	{
		alert("工号不能为空!");
		return false;
	}
	
	document.form1.mehtod="post";
	document.form1.action="teacherClass.jsp";
	document.form1.submit();
	return true; 
}

function studentCheck()
{
	if(document.form1.jobNumber.value=='')
	{
		alert("工号不能为空!");
		return false;
	}
	
	document.form1.action="studentDispose.jsp";
	document.form1.submit();

}

studentDispose.jsp

<%@ page  pageEncoding="UTF-8"  import ="java.sql.*"  import="java.util.*" %>

显示学生信息

	<%! String sNumber , sname , sex ,telephone , home ; int age ,score;%>
	<%
		String jobNumber = request.getParameter("jobNumber");
		Connection con;
		PreparedStatement pstmt;
		ResultSet rs=null;
		String sql=null;
		String driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
		String url = "jdbc:sqlserver://localhost:1433;DatabaseName=LCBCom";
		String user = "sa";
		String userPassword = "123";
		Class.forName(driver);
		con = DriverManager.getConnection(url , user , userPassword);
		sql="select s# , sname , score,age,sex,telephone,home  from S  where s#=? ";
		pstmt = con.prepareStatement(sql);
		pstmt.setString(1 , jobNumber);
		rs = pstmt.executeQuery();
		if(rs.next())
		{ 

		  sNumber= rs.getString("s#");   //String 是 s#报错重复的变量s# , 为什么?
		  sname = rs.getString("sname");
		  score = rs.getInt("score");
		  age = rs.getInt("age");
		  sex = rs.getString("sex");
		  telephone = rs.getString("telephone");
		  home  = rs.getString("home");
		if(sex.equals("M"))
		{
			sex="男";
		}
		else
		{
			sex="女";
		}
		rs.close();
		pstmt.close();
		con.close();

		//将学生用户信息存储在session中
		session.setAttribute("sNumber" ,  sNumber );  //直接写变量,不用放在表达式里
		session.setAttribute("sname"  , sname );
		session.setAttribute("score"  , score );
		session.setAttribute("age"  , age );
		session.setAttribute("sex" , sex );
		session.setAttribute("telephone" ,   telephone);
		session.setAttribute("home" ,  home );
	}
	else{


	%>
	
		
	
	<%
		}
	%>
	

你的信息如下:


numberError.jsp

<%@ page  pageEncoding="UTF-8" %>


<%
	String errorNumber = request.getParameter("jobNumber");
%>

无法识别学号<%= errorNumber %>,请检查学号是否输入正确!

5秒后将返回登录界面

<% response.setHeader("Refresh" , "5;url=register.jsp"); %>

studentModification.jsp

<%@ page  pageEncoding="UTF-8"   import ="java.sql.*"  import="java.util.*" %>


	<%
		session = request.getSession();
		String sNumber = (String)session.getAttribute("sNumber");
		String sname  = (String)session.getAttribute("sname");
		Object o;
		o  = session.getAttribute("score");
		String score = o.toString();
		o = session.getAttribute("age");
		String age = o.toString();
		String sex = (String)session.getAttribute("sex");
		String telephone  = (String)session.getAttribute("telephone");
		String home  = (String)session.getAttribute("home");

		if(sex.equals("男"))
		{
			sex = "M";
		}
		else
		{
			sex = "W";
		}
		Connection con;
		PreparedStatement pstmt;

		String driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
		String url = "jdbc:sqlserver://localhost:1433;DatabaseName=LCBCom";
		String user = "sa";
		String userPassword = "123";
		Class.forName(driver);
		con = DriverManager.getConnection(url , user , userPassword);

		String sql = "update S  set s#=? , sname = ? , score = ? , age = ? , sex = ? , telephone = ? , home = ?  where s# = ? ";
		pstmt = con.prepareStatement(sql);
		pstmt.setString(1 , sNumber);
		pstmt.setString(2 , sname);
		pstmt.setInt(3 , Integer.parseInt(score));
		pstmt.setInt(4 , Integer.parseInt(age));
		pstmt.setString(5 , sex);
		pstmt.setString(6 , telephone);
		pstmt.setString(7 , home);
		pstmt.setString(8 , sNumber);
		pstmt.executeUpdate();

		pstmt.close();
		con.close();

		
	%>
	

数据更新完成,将在5秒后返回主界面

<% response.setHeader("Refresh" , "5;url=register.jsp"); %>

已更新的数据如下:

成绩:<%= score %>

姓名:<%= sname %>

学号:<%= sNumber %>

性别:<%= sex %>

年龄:<%= age %>

联系方式:<%= telephone %>

居住地:<%= home %>

teacherClass.jsp

<%@ page  pageEncoding="UTF-8"  import ="java.sql.*"  import="java.util.*"  %>


	<%! String tname , title; %>
	<%
		String jobNumber = request.getParameter("jobNumber");
		jobNumber.trim();
		session.setAttribute("t#" ,jobNumber);
		Connection con;
		PreparedStatement pstmt;
		ResultSet rs=null;
		String driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
		String url = "jdbc:sqlserver://localhost:1433;DatabaseName=LCBCom";
		String user = "sa";
		String userPassword = "123";
		Class.forName(driver);
		con = DriverManager.getConnection(url , user , userPassword);

		String sql = "select c# , cname , tname , title  from T where t# = ?";
		pstmt = con.prepareStatement(sql);
		pstmt.setString(1 , jobNumber);
		rs = pstmt.executeQuery();
		String ArrayCname[] = new  String[10];
		String ArrayCnumber[] = new String[10];
		int i=0;
		while(rs.next())
		{
			tname = rs.getString("tname");
			title = rs.getString("title");
			ArrayCname[i] = rs.getString("cname");
			ArrayCnumber[i] = rs.getString("c#");
			//原来的设计里没有获取c#的想法,跳转到showinfo.jsp页面后,是根据cname的值查找c# ,然后又根据c#找的学生表的数据.这时要对学生表和教工表做外连接,不太好.
			//所以现在直接把c#也请求过来,然后单选框的value是c#的值,而对应的显示的是cname. 之后只需要查找学生表即可.
			i++;
		}

		rs.close();
		pstmt.close();
		con.close();
		
	%>

	
	
学号:<%= sNumber %>
姓名:<%= sname %>
年龄:<%= age %>
成绩:<%= score %>
性别:<%= sex %>
联系方式:<%= telephone %>
居住地:<%= home %>
修改个人信息:

选择你的课程进入系统

<%= tname %><%= title %>,请您选课

<% int u=0; while(u"+ ArrayCname[u]+""); u++; } %>

showInfo.jsp

s
<%@ page  pageEncoding="UTF-8"  import ="java.sql.*"  import="java.util.*"  %>


	

学生信息:

<%! String cnumber , snumber; %> <% session = request.getSession(); Object o = session.getAttribute("t#"); String c = o.toString(); cnumber = request.getParameter("Cnumber"); //接收到的是实际的c#值 , 变量写c# 报错说变量c重复定义,估计是#特殊字符 Connection con; PreparedStatement pstmt; ResultSet rs=null; String driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver"; String url = "jdbc:sqlserver://localhost:1433;DatabaseName=LCBCom"; String user = "sa"; String userPassword = "123"; Class.forName(driver); con = DriverManager.getConnection(url , user , userPassword); String sql = "select s# ,sname ,score ,age ,sex , telephone , home from S where c# = ?"; pstmt = con.prepareStatement(sql); pstmt.setString(1 , cnumber); rs = pstmt.executeQuery(); while(rs.next()) { %> <% snumber = rs.getString("s#"); %> <% String sex = rs.getString("sex"); if(sex.equals("M")) { sex = "男"; } else { sex = "女"; } session.setAttribute("showInfo_snumber" , snumber); session.setAttribute("showInfo_cnumber" , cnumber); %> <% } %>
学号姓名年龄性别联系方式成绩修改成绩
<%= rs.getString("s#") %><%= rs.getString("sname")%> <%= rs.getInt("age") %><%= sex %> <%= rs.getString("telephone") %> <%= rs.getInt("score") %> 修改成绩

创建学生身份信息

addStudentInfo.jsp

<%@ page  pageEncoding="UTF-8"  import ="java.sql.*"  import="java.util.*"  %>


<%
	 	session = request.getSession();
		Object o = session.getAttribute("showInfo_cnumber");
		String cnumber = o.toString();
%>

finallAddInfo.jsp

<%@ page  pageEncoding="UTF-8"  import ="java.sql.*"  import="java.util.*"  %>


	<%
		String sname = request.getParameter("sname");
		String age =  request.getParameter("age");
		String snumber =  request.getParameter("snumber");
		String telephone = request.getParameter("telephone");
		String home = request.getParameter("home");
		String sex = request.getParameter("sex");
		String score = request.getParameter("score");

		int  age_new = Integer.parseInt(age);
		int score_new = Integer.parseInt(score);

		session = request.getSession();
		Object o = session.getAttribute("showInfo_cnumber");
		String cnumber = o.toString();
		Connection con;
		PreparedStatement pstmt;
		String driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
		String url = "jdbc:sqlserver://localhost:1433;DatabaseName=LCBCom";
		String user = "sa";
		String userPassword = "123";
		Class.forName(driver);
		con = DriverManager.getConnection(url , user , userPassword);

		String sql = "insert into S(s# ,c# ,age ,sex ,home ,telephone , score ,sname) values(?, ? ,? ,? ,?,? , ? ,?)";
		pstmt = con.prepareStatement(sql);
		pstmt.setString(1 , snumber);
		pstmt.setString(2 , cnumber);
		pstmt.setInt(3 , age_new);
		pstmt.setString(4 , sex);
		pstmt.setString(5 , home);
		pstmt.setString(6 , telephone);
		pstmt.setInt(7 , score_new);
		pstmt.setString(8 ,sname);
		pstmt.executeUpdate();
	%>
	

学生成绩插入成功!将在5秒后返回登录界面

<% response.setHeader("Refresh" , "5;url=register.jsp"); %>

modification.jsp

<%@ page  pageEncoding="UTF-8"  import ="java.sql.*"  import="java.util.*"  %>


	<% 
		session = request.getSession();
		Object o = session.getAttribute("showInfo_snumber");
		String snumber = o.toString();
		Connection con;
		PreparedStatement pstmt;
		ResultSet rs=null;
		String driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
		String url = "jdbc:sqlserver://localhost:1433;DatabaseName=LCBCom";
		String user = "sa";
		String userPassword = "123";
		Class.forName(driver);
		con = DriverManager.getConnection(url , user , userPassword);

		String  sql = "select sname ,score from S where s# = ? ";
		pstmt = con.prepareStatement(sql);
		pstmt.setString(1 , snumber);
		rs = pstmt.executeQuery();
		rs.next();
		String sname = rs.getString("sname");
		int  score = rs.getInt("score");
		session.setAttribute("Modification_snumber" ,  snumber );
		rs.close();
		pstmt.close();
		con.close();
		
	%>
	
	
		
姓名:
年龄:
性别:
学号:
联系方式:
居住地:
成绩:
<%= cnumber %>

成绩修订

姓名:<%= sname %>
学号:<%= snumber %>
当前成绩:<%= score %>
修订后的成绩:

finallyScoreModification.jsp

<%@ page  pageEncoding="UTF-8"  import ="java.sql.*"  import="java.util.*"  %>


	<%! String snumber; %>
	<%
		session = request.getSession();
		String score = request.getParameter("score");
		int int_score = Integer.parseInt(score);
		Object o = session.getAttribute("Modification_snumber");
		snumber = o.toString();
		
		Connection con;
		PreparedStatement pstmt;
		
		String driver = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
		String url = "jdbc:sqlserver://localhost:1433;DatabaseName=LCBCom";
		String user = "sa";
		String userPassword = "123";
		Class.forName(driver);
		con = DriverManager.getConnection(url , user , userPassword);

		String sql = "update S set score = ? where s# = ?" ;
		pstmt = con.prepareStatement(sql);
		pstmt.setInt(1 , int_score);
		pstmt.setString(2 , snumber);
		pstmt.executeUpdate();
	%>
	

修改成绩成功!将在5秒后返回登录界面

<% response.setHeader("Refresh" , "5;url=register.jsp"); %>

数据库建表代码:

use LCBCom
--s# , c# ,sname , score,age,sex,telephone,home
create table S
(
	id int identity(1,1),
	s# varchar(20)  constraint PK_S_s# primary key,
	c# varchar(20) ,
	sname  char(6) default '',
	score  int  check(score<100  and score >0),
	age    int  check(age<50 and age>0),
	telephone  char(20) default '',
	home  varchar(40)  default ''
)

use LCBCom
alter table S
add sex char(1) 
go      -- 忘加了sex


use LCBCom
--s# , c# ,sname , score,age,sex,telephone,home
alter table S
add foreign key(c#) references T(c#)
on update cascade
on delete no action
go
--on 之后没格式没有{} , 直接写关键字,而且在创建外键之前必须已近存在外键



use LCBCom
--c#,cname,title,t#,tname
create table T
(
	c# varchar(20) constraint PK_T_c# primary key,
	cname char(10) ,
	tname char(4) , 
	t# varchar(20),
	title char(6)
)


use LCBCom
insert into  dbo.S(s# , c# , sname , score , age ,sex,telephone , home)
values ('201665748339' , '0010' ,'王佳 ',34 ,21 ,'W ' ,'18865673382' ,  '哈尔滨江北区学海街1006室')
go

use LCBCom
insert into T(c# ,cname ,tname ,t# , title)
values('0000' ,'javaWeb开发教程 ',  '张娜' , '20160000' ,'教授')
go

选取部分源数据:

T表源数据示例:
c#             cname                                 tname                t#                                            title
0000           javaWeb开发教程                       张娜                 20160000                                      教授
0001           数据结构                              严为民               20160001                                      副教授
0010           c语言程序设计                         谭浩强               20160010                                      讲师
0011           python程序设计教程                    林兴良               20160011                                      讲师


S表源数据示例:
s#                 c#                   sname         score      age     sex      telephone                         home
201662025056       0000                 张三          78         20      M        18846791756                       哈尔滨江北区学海街1006室
201662979907       0001                 李四          88         19      W        18846782389                       哈尔滨江北区学海街1006室
201666387629       0001                 王五          89         19      M        18837893338                       哈尔滨江北区学海街1006室

201665748339       0010                 王佳          34         21      W        18865673382                       哈尔滨江北区学海街1006室


最后,链接数据库用到的用户名是  sa  密码:123   可以自行按需求更改



你可能感兴趣的:(个人项目)