首页 > 代码库 > 小项目之学生报到管理系统
小项目之学生报到管理系统
学生报到管理系统:
假定学生报到的流程如下:
系统报到(分班)->财务交费(交学费)->宿舍分配(分宿舍)
系统功能需求:
1.基础数据管理模块:
<1.专业设置
<2.学生名册
<3.宿舍情况
<4.班级设置
<5.报到状况查询
<6.用户管理
2.报到分班管理:
<1.报到分班
<2.分班情况查询
3.报到收费管理:
<1.收费情况登记
<2.收费情况查询
4.学生宿舍管理:
<1.宿舍分配
<2.宿舍情况查询
除了以上模块以外,还有一个用户登录功能。不同用户具有不同身份,不同身份的管理员可以使用不同的功能。
本项目的所有数据处理逻辑,业务逻辑,数据表现逻辑都在JSP页面中完成,系统是最简单的二层结构:JSP<---->数据库。数据库采用mysql。
1.数据库系统的实现:
create database StudentManageSystem;
use StudentManageSystem;
create table Student(
StudentId int not null primary key,
StudentName varchar(40),
SpecialityId int, //专业
ClassId int,
BedchamberId int, //宿舍
PayAmount int,
PayOk char(1),
RegistDate date,
MatriNo varchar(20); //录取通知书号
);
create table Adminuser(
Adminusername varchar(40) not null primary key,
Adminuserpassword varchar(40),
Adminuserrole int
);
create table Classtt(
ClassId int not null primary key,
ClassName varchar(40)
);
create table Speciality(
SpecialityId int not null primary key,
SpecialityName varchar(40)
);
create table Bedchamber(
BedchamberId int not null primary key,
BedchamberName varchar(40)
);
alter table Student add constraint FK_Student_Bedchamber foreign key(
BedchamberId
)references Bedchamber(
BedchamberId
);
alter table Student add constraint FK_Student_Classtt foreign key(
ClassId
)references Classtt(
ClassId
);
alter table Student add constraint FK_Student_Speciality foreign key(
SpecialityId
)references Spciality(
SpecialityId
);
2.插入数据:
INSERT INTO Speciality VALUES(11,‘微电子‘);
INSERT INTO Speciality VALUES(12,‘自动化‘);
INSERT INTO Speciality VALUES(13,‘计算机‘);
INSERT INTO Speciality VALUES(14,‘软件‘);
INSERT INTO Speciality VALUES(15,‘会计‘);
INSERT INTO Speciality VALUES(16,‘英语‘);
INSERT INTO Speciality VALUES(17,‘财经‘);
INSERT INTO Adminuser VALUES(‘admin‘,‘admin‘,1);
INSERT INTO Adminuser VALUES(‘wuenqiang‘,‘wuenqiang‘,2);
INSERT INTO Adminuser VALUES(‘mosquito‘,‘mosquito‘,3);
INSERT INTO Adminuser VALUES(‘punkhippie‘,‘punkhippie‘,4);
INSERT INTO Classtt VALUES(1,‘one‘);
INSERT INTO Classtt VALUES(2,‘two‘);
INSERT INTO Classtt VALUES(3,‘three‘);
INSERT INTO Classtt VALUES(4,‘four‘);
INSERT INTO Classtt VALUES(5,‘five‘);
INSERT INTO Classtt VALUES(6,‘six‘);
INSERT INTO Classtt VALUES(7,‘seven‘);
INSERT INTO Classtt VALUES(8,‘eight‘);
INSERT INTO Classtt VALUES(9,‘nine‘);
INSERT INTO Bedchamber VALUES(1,‘one‘);
INSERT INTO Bedchamber VALUES(2,‘two‘);
INSERT INTO Bedchamber VALUES(3,‘three‘);
INSERT INTO Bedchamber VALUES(4,‘four‘);
INSERT INTO Bedchamber VALUES(5,‘five‘);
INSERT INTO Bedchamber VALUES(6,‘six‘);
INSERT INTO Bedchamber VALUES(7,‘seven‘);
INSERT INTO Bedchamber VALUES(8,‘eight‘);
INSERT INTO Bedchamber VALUES(9,‘nine‘);
INSERT INTO Student VALUES(01,‘吴恩强‘,11,1,1,6000,‘y‘,‘2014-05-01‘,3111001);
INSERT INTO Student VALUES(02,‘吴晓强‘,12,1,1,6000,‘y‘,‘2014-05-02‘,3111001);
INSERT INTO Student VALUES(03,‘吴小强‘,13,1,1,6000,‘y‘,‘2014-05-03‘,3111001);
INSERT INTO Student VALUES(04,‘吴强强‘,14,1,1,6000,‘y‘,‘2014-05-02‘,3111001);
INSERT INTO Student VALUES(05,‘吴恩恩‘,15,1,1,6000,‘y‘,‘2014-05-01‘,3111001);
INSERT INTO Student VALUES(06,‘吴强恩‘,16,1,1,6000,‘y‘,‘2014-05-03‘,3111001);
3.设计总体页面效果:
讲一个页面拆分为三个部分,每部分各是一个网页,如图。
-----index.jsp-----
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | <%@ page contentType= "text/html;charset=GBK" %> <% if (session.getAttribute( "adminusername" )== null ||session.getAttribute( "adminusername" ).toString().length()== 0 ) response.sendRedirect( "login.jsp" ); %> <html> <head> <title>报道管理系统</title> </head> <frameset framespacing= "0" border= "0" frameborder= "0" rows= "64,*" marginwidth= "0" marginheight= "0" > <frame name= "banner" scrolling= "no" noresize target= "contents" src=http://www.mamicode.com/ "banner.html" > <frameset cols= "160,*" > <frame name= "left" target= "main" scrolling= "auto" src=http://www.mamicode.com/ "left.jsp" marginwidth= "10" marginheight= "0" > <frame name= "main" scrolling= "auto" marginwidth= "0" marginheight= "0" src=http://www.mamicode.com/ "regstatus.jsp" > </frameset> <noframes> <body> </body> </noframes> </frameset> </html> |
首先检查adminusername的内容是否为空,如果是则用户没有登陆,页面重定向到login.jsp页面要求用户重新登陆。
-----left.jsp-----
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 | <%@ page contentType= "text/html;charset=GBK" %> <html> <head><title>登陆系统</title></head> <body> <div align= "center" > <table border= "1" cellpadding= "0" cellspacing= "0" style= "border-collapse:collapse" bordercolor= "#c0c0c0" width= "140" > <%String adminuserrole=session.getAttribute( "adminuserrole" )+ "" ; int adminuserroleint= 0 ; if (adminuserrole!= null &&adminuserrole.length()!= 0 ) adminuserroleint=Integer.parseInt(adminuserrole); %> <% if (adminuserroleint== 1 ||adminuserroleint== 2 ){ %> <tr> <td width= "100%" bgcolor= "#c0c0c0" align= "center" > <font color= "#0000ff" >报到分班管理</font> </td> </tr> <tr> <td width= "100%" align= "center" > <font><a href=http://www.mamicode.com/ "classadmin.jsp" target= "main" >报到分班</a></font> </td> </tr> <tr> <td width= "100%" align= "center" > <font><a href=http://www.mamicode.com/ "classview.jsp" target= "main" >分班情况查询</a></font> </td> </tr> <%} %> <% if (adminuserroleint== 1 ||adminuserroleint== 3 ){ %> <tr> <td width= "100%" bgcolor= "#c0c0c0" align= "center" > <font color= "#0000ff" >报到收费管理</font> </td> </tr> <tr> <td width= "100%" align= "center" > <font><a href=http://www.mamicode.com/ "acceptmoney.jsp" target= "main" >收费情况登记</a></font> </td> </tr> <tr> <td width= "100%" align= "center" > <font><a href=http://www.mamicode.com/ "classview.jsp" target= "main" >收费情况查询</a></font> </td> </tr> <%} %> <% if (adminuserroleint== 1 ||adminuserroleint== 4 ){ %> <tr> <td width= "100%" bgcolor= "#c0c0c0" align= "center" > <font color= "#0000ff" >学生宿舍管理</font> </td> </tr> <tr> <td width= "100%" align= "center" > <font><a href=http://www.mamicode.com/ "bedchamber.jsp" target= "main" >宿舍分配</a></font> </td> </tr> <tr> <td width= "100%" align= "center" > <font><a href=http://www.mamicode.com/ "classview.jsp" target= "main" >宿舍情况查询</a></font> </td> </tr> <%} %> <% if (adminuserroleint== 1 ){ %> <tr> <td width= "100%" bgcolor= "#c0c0c0" align= "center" > <font color= "#0000ff" >基础数据管理</font> </td> </tr> <tr> <td width= "100%" align= "center" > <font><a href=http://www.mamicode.com/ "specialityadmin.jsp" target= "main" >录入专业</a></font> </td> </tr> <tr> <td width= "100%" align= "center" > <font><a href=http://www.mamicode.com/ "matri.jsp" target= "main" >录入录取学生名册</a></font> </td> </tr> <tr> <td width= "100%" align= "center" > <font><a href=http://www.mamicode.com/ "bedchamber.jsp" target= "main" >录入宿舍</a></font> </td> </tr> <tr> <td width= "100%" align= "center" > <font><a href=http://www.mamicode.com/ "class.jsp" target= "main" >录入班级</a></font> </td> </tr> <tr> <td width= "100%" align= "center" > <font><a href=http://www.mamicode.com/ "regstatus.jsp" target= "main" >学生报道状况查询</a></font> </td> </tr> <tr> <td width= "100%" align= "center" > <font><a href=http://www.mamicode.com/ "adminuser.jsp" target= "main" >用户管理</a></font> </td> </tr> <%} %> </table> </div> </body> </html> |
通过session变量daminuserrole的值来获取用户角色,根据用户角色来相应的显示可操作的功能菜单。
4.系统功能的实现:
用户登陆功能的实现:
-----login.jsp-----
<%@ page contentType="text/html;charset=GBK" %> <%@ page import="com.bjsxt.DB.*,java.sql.*" %> <%Connection conn=DBConn.createDBConn(); %> <% String adminusername=request.getParameter("adminusername"); String adminuserpassword=request.getParameter("adminuserpassword"); String action=request.getParameter("action"); String errormsg=request.getParameter("errormsg"); if(action != null && action.trim().equals("login")){ String sql="select * from Adminuser where Adminusername=? and Adminuserpassword=?"; PreparedStatement state=conn.prepareStatement(sql); state.setString(1,adminusername); state.setString(2,adminuserpassword); ResultSet rs=state.executeQuery(); if(rs.next()) { session.setAttribute("adminusername",adminusername); session.setAttribute("adminuserrole",rs.getString("Adminuserrole")); response.sendRedirect("index.jsp"); } } %> <html> <body> <br><br><br><br> <div align="center"> <form method="post" action="login.jsp"> <table table border="1" cellpadding="0" cellspacing="0" style="border-collapse:collapse" bordercolor="#c0c0c0" width="300"> <tr> <td width="100%" bgcolor="#c0c0c0" align="center"> <font color="#0000ff">用户登录</font> </td> </tr> <% if(errormsg!=null&&errormsg.length()!=0){ %> <tr> <td align="center"> <%=errormsg %> </td> </tr> <% } %> <tr> <td> 请输入用户名:<input type="text" name="adminusername"><br> 请输入密 码:<input type="password" name="adminuserpassword"><br> <input type="submit" value=http://www.mamicode.com/"提 交"> <input type="hidden" name="action" value=http://www.mamicode.com/"login"> </td> </tr> </table> </form> </div> </body> </html> <%DBConn.closeConn(conn); %>
为防止SQL注入攻击,使用了PreparedStatement对象来执行带参数的SQL语句。如果校验没有通过,则将错误的提示文件放入字符串errormsg中,在后续的代码显示表格时,
如果errormsg的值不为空,说明有错误信息,则显示出来。
-----DBConn.java-----
<%@ page contentType="text/html;charset=GBK" %> <%@ page import="com.bjsxt.DB.*,java.sql.*" %> <%Connection conn=DBConn.createDBConn(); %> <% String adminusername=request.getParameter("adminusername"); String adminuserpassword=request.getParameter("adminuserpassword"); String action=request.getParameter("action"); String errormsg=request.getParameter("errormsg"); if(action != null && action.trim().equals("login")){ String sql="select * from Adminuser where Adminusername=? and Adminuserpassword=?"; PreparedStatement state=conn.prepareStatement(sql); state.setString(1,adminusername); state.setString(2,adminuserpassword); ResultSet rs=state.executeQuery(); if(rs.next()) { session.setAttribute("adminusername",adminusername); session.setAttribute("adminuserrole",rs.getString("Adminuserrole")); response.sendRedirect("index.jsp"); } } %> <html> <body> <br><br><br><br> <div align="center"> <form method="post" action="login.jsp"> <table table border="1" cellpadding="0" cellspacing="0" style="border-collapse:collapse" bordercolor="#c0c0c0" width="300"> <tr> <td width="100%" bgcolor="#c0c0c0" align="center"> <font color="#0000ff">用户登录</font> </td> </tr> <% if(errormsg!=null&&errormsg.length()!=0){ %> <tr> <td align="center"> <%=errormsg %> </td> </tr> <% } %> <tr> <td> 请输入用户名:<input type="text" name="adminusername"><br> 请输入密 码:<input type="password" name="adminuserpassword"><br> <input type="submit" value=http://www.mamicode.com/"提 交"> <input type="hidden" name="action" value=http://www.mamicode.com/"login"> </td> </tr> </table> </form> </div> </body> </html> <%DBConn.closeConn(conn); %>
这个类中有两个静态的方法,一个用于生成一个数据库连接对象,一个用于关闭数据库连接。
-----specialityadmin.jsp-----
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 | <% @page contentType= "text/html;charset=GBK" %> <% @page import = "com.bjsxt.DB.*,java.sql.*" %> <%Connection conn=DBConn.createDBConn(); %> <html> <body> <% //----获取请求参数值 String action=request.getParameter( "action" ); if (action!= null &&action.length()!= 0 ) action= new String(action.getBytes( "ISO-8859-1" )); String specialityname=request.getParameter( "specialityname" ); if (specialityname!= null &&specialityname.length()!= 0 ) specialityname= new String(specialityname.getBytes( "ISO-8859-1" )); String specialityid=request.getParameter( "specialityid" ); if (specialityid!= null &&specialityid.length()!= 0 ) specialityid= new String(specialityid.getBytes( "ISO-8859-1" )); //----如果想增加一个专业 if ( "add" .equals(action)){ String sql= "selet * from Spciality where SpecialityName=?" ; PreparedStatement preSQLSelect=conn.prepareStatement(sql); preSQLSelect.setString( 1 ,specialityname); ResultSet rs=preSQLSelect.executeQuery(); if (!rs.next()){ sql= "insert into Speciality(SpecialityName) values(?)" ; PreparedStatement preSQLInsert=conn.prepareStatement(sql); preSQLInsert.setString( 1 ,specialityname); preSQLInsert.executeUpdate(); } } //----如果是删除一个专业---- if ( "del" .equals(action)){ String sql= "delete from Speciality where SpecialityId=?" ; PreparedStatement preSQLDel=conn.prepareStatement(sql); int specialityidInt= 0 ; if (specialityid!= null &&specialityid.length()> 0 ){ specialityidInt=Integer.parseInt(specialityid); preSQLDel.setInt( 1 ,specialityidInt); preSQLDel.executeUpdate(); } } %> <form method= "post" action= "specialityadmin.jsp" > <table border= "1" cellpadding= "0" cellspacing= "0" style= "border-collapse:collapse" bordercolor= "#c0c0c0" width= "600" > <tr> <td width= "100%" bgcolor= "#c0c0c0" > <font color= "#0000ff" >录入专业数据</font></td> </tr> <tr> <td width= "100%" > 请输入专业名称: <input type= "text" name= "specialityname" > <input type= "hidden" name= "action" value=http://www.mamicode.com/ "add" > <imput type= "submit" value=http://www.mamicode.com/ "提交" > </td> </tr> </table> </form> <table border= "1" cellpadding= "0" cellspacing= "0" style= "border-collapse:collapse" bordercolor= "#c0c0c0" width= "600" > <tr> <td width= "100%" bgcolor= "#c0c0c0" align= "center" colspan= "3" > <font color= "#0000ff" >已有专业数据</font></td> </tr> <tr> <td width= "20%" align= "center" > 序号 </td> <td width= "60%" align= "center" > 专业名称 </td> <td width= "20%" align= "center" > 删除? </td> </tr> <% //----查询出已有的专业名称 String sql= "select * from Speciality" ; Statement state=conn.createStatement(); ResultSet rs=state.executeQuery(sql); int i= 0 ; while (rs.next()){ i++; %> <tr> <td width= "20%" align= "center" > <%=i%> </td> <td width= "60%" align= "center" > <%=rs.getString( "SpecialityName" )%> </td> <td width= "20%" align= "center" > <a href=http://www.mamicode.com/ "specialityadmin.jsp?action=del&specialityid=<%=rs.getInt(" SpecialityId ") %>" >删除</a> </td> </tr> <% } %> </table> </body> </html> <%DBConn.closeConn(conn);%> |
在表单中使用了一个名为action的隐藏域,值为add,表明是要增加一个专业;在删除的超链接中也带了action参数,值为del,表示要删除一个专业。再页面的第一个JSP程序块中首先接收传来的参数。为了解决中文乱码问题,对提交的数据做了编码转换。根据action的值的判断,作出不同的处理。
-----classadmin.jsp-----
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | <% @page contentType= "text/html;charset=GBK" %> <% @page import = "com.bjsxt.DB.*,java.sql.*" %> <%Connection conn=DBConn.createDBConn(); %> <% //----获取请求参数值---- String studentname=request.getParameter( "studentname" )+ "" ; if (studentname!= null &&studentname.length()!= 0 ) studentname= new String(studentname.getBytes( "ISO-8859-1" )); String action=request.getParameter( "action" )+ "" ; String matrino=request.getParameter( "matrino" )+ "" ; //----构造查询的SQL语句---- String sqlwhere= new String( "" ); String sql= new String( "" ); if ( "select" .equals(action)){ if (studentname!= null &&studentname.trim().length()!= 0 ) sqlwhere= "where studentname like ‘%" +studentname.trim()+ "%‘ " ; if (sqlwhere!= null &&sqlwhere.length()!= 0 ){ if (matrino!= null &&matrino.trim().length()!= 0 ) sqlwhere+= " and matrino like ‘%" +matrino.trim()+ "%‘" ; } else { if (matrino!= null &&matrino.trim().length()!= 0 ) sqlwhere= " where matrino like ‘%" +matrino.trim()+ "%‘" ; } sql= "select * from student " +sqlwhere; } //----设置分班情况---- if ( "update" .equals(action)){ //如果设置分班情况 String studentcount=request.getParameter( "studentcount" ); for ( int i= 1 ;i<=Integer.parseInt(studentcount);i++){ String studentid=request.getParameter( "studentid" +i); String classid=request.getParameter( "classid" +i); if (classid!= null &&classid.length()!= 0 &&studentid!= null &&studentid.length()!= 0 ){ String sqlstr= "update student set classid=" +classid+ " where studentid=" +studentid+studentid; Statement state=conn.createStatement(); state.executeQuery(sqlstr); } } out.print( "设置分班操作成功!" ); } %> <html> <body> <form method= "post" action= "calssadmin.jsp" > <table border= "1" cellpadding= "0" cellspacing= "0" style= "border-collapse:collapse" bordercolor= "#c0c0c0" width= "700" > <tr> <td width= "100%" bgcolor= "#c0c0c0" > <font color= "#0000ff" >要查询的条件</font></td> </tr> <tr> <td width= "100%" > 请输入姓名: <input type= "text" name= "studentname" > 请输入录取通知书号: <input type= "text" name= "matrino" > <input type= "hidden" name= "action" value=http://www.mamicode.com/ "select" > <input type= "submit" name= "提交" > </td> </tr> </table> </form> <form action= "calssadmin.jsp" method= "post" > <table border= "1" cellpadding= "0" cellspacing= "0" style= "border-collapse:collapse" bordercolor= "#c0c0c0" width= "700" > <tr> <td width= "100%" bgcolor= "#c0c0c0" align= "center" colspan= "8" > <font color= "#0000ff" >查询到的学生数据</font></td> </tr> <tr> <td width= "5%" align= "center" >序号</td> <td width= "12%" align= "center" >姓名</td> <td width= "16%" align= "center" >录取通知书号</td> <td width= "12%" align= "center" >录取班级</td> <td width= "15%" align= "center" >所在班级</td> </tr> <% if ( "select" .equals(action)){ %> <%Statement state=conn.createStatement(); ResultSet rs=state.executeQuery(sql); int i= 0 ; while (rs.next()){ i++; %> <tr> <td width= "5%" align= "center" ><%=i%></td> <td width= "12%" align= "center" ><%=rs.getString( "studentname" )%></td> <td width= "16%" align= "center" ><%=rs.getString( "matrino" )%></td> <td width= "12%" align= "center" > <% int specialityid=rs.getInt( "specialityid" ); if (specialityid== 0 ) out.print( "尚无专业" ); else { sql= "select * from speciality where specialityid=" +specialityid; Statement statetemp=conn.createStatement(); ResultSet rstemp=statetemp.executeQuery(sql); if (rstemp.next()) out.print(rstemp.getString( "specialityname" )); else out.print( "尚无专业" ); } %> </td> <td width= "15%" align= "center" > <input type= "hidden" name= "<%=" studentid "+i%>" value=http://www.mamicode.com/ "<%=rs.getString(" studentid ")%>" > <select name= "<%=" classid "+i%>" > <option value=http://www.mamicode.com/ "" >==尚未分班==</option> <% int classid=rs.getInt( "classid" ); sql= "select * from classtt" ; Statement statetemp=conn.createStatement(); ResultSet rstemp=statetemp.executeQuery(sql); while (rstemp.next()){ int rstempclassid=rstemp.getInt( "classid" );%> <option value=http://www.mamicode.com/ "<%=rstempclassid%>" <% if (rstempclassid==classid){%>selected<%} %>> <%=rstemp.getString( "classname" ) %> </option> <%} %> </select> </td> </tr> <%} %> <tr> <td width= "100%" bgcolor= "#c0c0c0" align= "center" colspan= "8" > <font color= "#0000ff" > <input type= "submit" value=http://www.mamicode.com/ "确 定" > </font></td> </tr> <input type= "hidden" name= "studentcount" value=http://www.mamicode.com/ "<%=i%>" > <input type= "hidden" name= "cation" value=http://www.mamicode.com/ "update" > <%} %> </table> </form> </body> </html> <%DBConn.closeConn(conn);%> |
-----acceptmoney-----
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 | <%@ page contentType= "text/html;charset=GBK" %> <%@ page import = "com.bjsxt.DB.*,java.sql.*" %> <%Connection conn=DBConn.createDBConn(); %> <% //----获取请求参数值---- String studentname=request.getParameter( "studentname" )+ "" ; if (studentname!= null &&studentname.length()!= 0 ) studentname= new String(studentname.getBytes( "ISO-8859-1" )); String action=request.getParameter( "action" )+ "" ; String matrino=request.getParameter( "matrino" )+ "" ; //----构造查询的SQL语句---- String sqlwhere= new String( "" ); String sql= new String( "" ); if ( "select" .equals(action)){ //如果是查询操作 if (studentname!= null &&studentname.trim().length()!= 0 ) sqlwhere= "where studentname like ‘%" +studentname.trim()+ "%‘ " ; if (sqlwhere!= null &&sqlwhere.length()!= 0 ){ if (matrino!= null &&matrino.trim().length()!= 0 ) sqlwhere+= " and matrino like ‘%" +matrino.trim()+ "%‘" ; } else { if (matrino!= null &&matrino.trim().length()!= 0 ) sqlwhere= " where matrino like ‘%" +matrino.trim()+ "%‘" ; } sql= "select * from student " +sqlwhere; } //----交费操作---- if ( "update" .equals(action)){ //如果是交费操作 String studentcount=request.getParameter( "studentcount" ); for ( int i= 1 ;i<=Integer.parseInt(studentcount);i++){ String studentid=request.getParameter( "studentid" +i); String payamount=request.getParameter( "payamount" +i)+ "" ; String payok=request.getParameter( "payok" +i)+ "" ; if (studentid!= null &&studentid.length()!= 0 &&payamount!= null &&payamount.length()!= 0 ){ String sqlstr= "update student set payamount=" +payamount+ "," + "payok=" +payok+ " where studentid=" +studentid; Statement state=conn.createStatement(); state.executeQuery(sqlstr); } } out.print( "收费情况登记成功!" ); } %> <html> <body> <form method= "post" action= "acceptmoney.jsp" > <table border= "1" cellpadding= "0" cellspacing= "0" style= "border-collapse:collapse" bordercolor= "#c0c0c0" width= "700" > <tr> <td width= "100%" bgcolor= "#c0c0c0" > <font color= "#0000ff" >要查询的条件</font></td> </tr> <tr> <td width= "100%" > 请输入姓名: <input type= "text" name= "studentname" > 请输入录取通知书号: <input type= "text" name= "matrino" > <input type= "hidden" name= "action" value=http://www.mamicode.com/ "select" > <input type= "submit" name= "提交" > </td> </tr> </table> </form> <form action= "acceptmoney.jsp" method= "post" > <table border= "1" cellpadding= "0" cellspacing= "0" style= "border-collapse:collapse" bordercolor= "#c0c0c0" width= "700" > <tr> <td width= "100%" bgcolor= "#c0c0c0" align= "center" colspan= "7" > <font color= "#0000ff" >查询到的学生数据</font></td> </tr> <tr> <td width= "5%" align= "center" >序号</td> <td width= "12%" align= "center" >姓名</td> <td width= "16%" align= "center" >录取通知书号</td> <td width= "12%" align= "center" >录取专业</td> <td width= "15%" align= "center" >所在班级</td> <td width= "15%" align= "center" >交费金额</td> <td width= "15%" align= "center" >是否交清</td> </tr> <% if ( "select" .equals(action)){ %> <%Statement state=conn.createStatement(); ResultSet rs=state.executeQuery(sql); int i= 0 ; while (rs.next()){ i++; %> <tr> <td width= "5%" align= "center" ><%=i%></td> <td width= "12%" align= "center" ><%=rs.getString( "studentname" )%></td> <td width= "16%" align= "center" ><%=rs.getString( "matrino" )%></td> <td width= "12%" align= "center" > <% int specialityid=rs.getInt( "specialityid" ); if (specialityid== 0 ) out.print( "尚无专业" ); else { sql= "select * from speciality where specialityid=" +specialityid; Statement statetemp=conn.createStatement(); ResultSet rstemp=statetemp.executeQuery(sql); if (rstemp.next()) out.print(rstemp.getString( "specialityname" )); else out.print( "尚无专业" ); } %> </td> <td width= "15%" align= "center" > <input type= "hidden" name= "<%=" studentid "+i%>" value=http://www.mamicode.com/ "<%=rs.getString(" studentid ")%>" > <% int classid=rs.getInt( "classid" ); boolean isclass= false ; sql= "select * from classtt where classid=" +classid; Statement statetemp=conn.createStatement(); ResultSet rstemp=statetemp.executeQuery(sql); if (rstemp.next()){ out.print(rstemp.getString( "classname" )); isclass= true ; } else { out.print( "尚未分班" ); } %> </td> <td width= "15%" align= "center" > <% if (isclass){ %> <inptu type= "text" name= "<%=" payamount "+i%>" value=http://www.mamicode.com/ "<%=rs.getFloat(" payamount ")%> size=" 12 "> <%} %> </td> <td width= "15%" align= "center" > <% if (isclass){ %> <inptu type= "radio" name= "<%=" payok "+i%>" value=http://www.mamicode.com/ "1" size= "12" <% if (rs.getInt( "payok" )== 1 ) out.print( "checked=true" ); %>>是 <inptu type= "radio" name= "<%=" payok "+i%>" value=http://www.mamicode.com/ "0" size= "12" <% if (rs.getInt( "payok" )== 0 ) out.print( "checked=true" ); %>>否 <%} %> </td> </tr> <%} %> <tr> <td width= "100%" bgcolor= "#c0c0c0" align= "center" colspan= "8" > <font color= "#0000ff" > <input type= "submit" value=http://www.mamicode.com/ "确 定" > </font></td> </tr> <input type= "hidden" name= "studentcount" value=http://www.mamicode.com/ "<%=i%>" > <input type= "hidden" name= "cation" value=http://www.mamicode.com/ "update" > <%} %> </table> </form> </body> </html> <%DBConn.closeConn(conn);%> |
如果已经分班且付清学费,则会显示一个宿舍下拉框,供操作人员选择宿舍。下拉框的option标签根据宿舍表中的记录条数来定,如果正要增加的option中,宿舍的ID号正好等于当前记录的宿舍ID号,则将此option标签设为selected,表示被选中。
难点:录取学生名册基础数据管理功能的实现-----matri.jsp-----
总结:
通过完成系统开发手动操作后,对软件工程的思想会有深一步的认识,对MyEclipse开发Web应用的方法也能熟练操作,对JSP只是的综合运用也更加灵活了。