标签:drive ext nts 查看 ret end 代码 app 部分
项目简述:
基于java web实现学生卡管理系统,用户包括学生和学生处,分别实现以下功能。
学生:
1.对本人登录密码的修改
2.申请补办学生卡
3.查看学生卡补办状态
学生处:
1.对学生信息的管理(包括对信息的增删改查)
2.受理学生证的补办申请
3.查询学生证补办记录
在此次javaweb的项目中,我采用mysql数据库对数据进行管理,前端界面采用JSP编写,利用JavaBean实现用户与数据库之间的映射。难点在于实现学生端与学生处端的信息互动,说到底都是利用嵌入式sql语言对mysql数据库的读取、更新与在前端页面显示的问题。编写代码期间,还设置了session变量,将页面中所涉及并且需要利用的用户变量储存在session变量中。
该项目基于mysql数据库,在mysql中创建studentcard数据库,并且在studentcard中建立admin(学生处)、student(学生)、apply_info(申请信息)、log(补办日志)四张表。
数据库操作代码:
Connection conn = null;
Statement st = null;
ResultSet rs = null;
public BaseDAO()
{
try{
Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://localhost:3306/studentcard";// 连接url字符串
String user = "root";// 数据库用户名
String password = "";// 数据库密码
this.conn=DriverManager.getConnection(url,user,password);
this.st=this.conn.createStatement();
this.rs=null;
}catch(Exception ex)
{ex.printStackTrace();
}
}
public String doUpgrade(String sql)
{ //数据库更新操作
try{
if(this.st!=null)
this.st.executeUpdate(sql);
return "";
}catch(Exception ex)
{
ex.printStackTrace();
return ex.getMessage();
}
}
public ResultSet doQuery(String sql)
{ //数据库查询操作
try{
this.rs=this.st.executeQuery(sql);
}catch(Exception ex)
{
ex.printStackTrace();
}
return this.rs;
}
//管理员身份验证登录关键代码
sql="select * from admin where id=‘"+user.getUserId()+"‘ and password= ‘"+user.getUserPassword()+"‘";
ResultSet rs=db.doQuery(sql);
if( rs.next())
{
String userName = rs.getString("name");
System.out.println("sessionUserName" + userName);
request.getSession().setAttribute("sessionUserId", user.getUserId());
request.getSession().setAttribute("sessionUserName", userName);
user.setPassed(true);
out.print("Success!");
response.sendRedirect("MainIndex.jsp");
}
else
{
out.print("<font color=red>用户名或口令不正确</font><br>");
}
//查询全部学生信息& 以表格的形式输出 关键代码
ResultSet rs=db.doQuery("select * from student");
out.println("学生信息如下:<br>");
out.println("<table border=1><thead><tr>");
out.println("<th>学号</th><th>姓名</th><th>学院</th><th>专业</th><th>密码</th></tr></thead>");
out.println("<tbody>");
while(rs.next())
{
String id=rs.getString("id");
String un=rs.getString("sname");
String co=rs.getString("college");
String dp=rs.getString("sdept");
String pd=rs.getString("password");
out.println("<tr><td>"+id+"</td>");
out.println("<td>"+un+"</td>");
out.println("<td>"+co+"</td>");
out.println("<td>"+dp+"</td>");
out.println("<td>"+pd+"</td></tr>");
}
out.println("</tbody></table>");
//学生申请补办学生卡 & 将申请信息插入到apply_info表中
String name=request.getParameter("name");
String id=request.getParameter("id");
String college=request.getParameter("college");
String department=request.getParameter("department");
String userId = session.getAttribute("sessionUserId").toString();
if(name!=null && id!=null && college!=null && department!=null && userId.equals(id))
{ String sql="insert into apply_info(id,sname,college,sdept,state) values("+ "‘"+ id+"‘,‘"+name+"‘,‘"+college+"‘,‘"+department+"‘,‘"+"未补办"+"‘)";
//System.out.println(sql);
String rs=db.doUpgrade(sql);
out.print("申请成功");
}
//完成补办
String id=request.getParameter("id");
String name = request.getParameter("name");
//System.out.println(id);
if(id != null){
String sql = "update apply_info set state = ‘补办完成‘ where id=‘" + id +"‘";
//System.out.println(sql);
String rs1 =db.doUpgrade(sql);
String userId = session.getAttribute("sessionUserId").toString();
String userName = session.getAttribute("sessionUserName").toString();
//System.out.println("userId = "+ userId);
//System.out.println("userUserName = "+ userName);
sql="insert into log(id,name,sid,sname) values("+"‘"+userId+"‘"+",‘"+userName+"‘,‘"+id+"‘,‘"+name+"‘)";
//System.out.println(sql);
String rs2 = db.doUpgrade(sql);
response.sendRedirect("Repair.jsp");
sql = "delete from apply_info where state = ‘补办完成‘";
String rs3 = db.doUpgrade(sql);
//response.sendRedirect("Repair.jsp");
}
//在apply_info表中读数据并且输出到jsp界面中,只能查看当前用户的受理补办状态
String userId = session.getAttribute("sessionUserId").toString();
System.out.println(userId);
String sql = "select * from apply_info where id = ‘" + userId+ "‘";
ResultSet rs=db.doQuery(sql);
if(rs.next()){
String id=rs.getString("id");
String name=rs.getString("sname");
String college=rs.getString("college");
String department = rs.getString("sdept");
String state = rs.getString("state");
out.print("您的补办信息:<br>");
out.print("........................................................................<br>");
out.print("学号:"+id+"<br/>");
out.print("姓名:"+name+"<br/>");
out.print("学院:"+college+"<br/>");
out.print("专业:" + department + "<br/>");
out.print("状态:" + state + "<br>");
out.print("........................................................................");
}else{
out.print("无申请,你看什么看!");
}
//从log表中读出所有的补办日志输出到JSP页面中
ResultSet rs=db.doQuery("select * from log");
out.println("发放记录如下:<br>");
out.println("..............................................................................................<br>");
while(rs.next())
{
String userId=rs.getString("id");
String userName=rs.getString("name");
String sid=rs.getString("sid");
String sname=rs.getString("sname");
//String pd=rs.getString("password");
out.print("管理员id:" + userId + " " );
out.println("管理员name:" + userName + "<br>");
out.print("学生id:" + sid + " ");
out.println("学生name:" + sname + "<br>");
out.println("............................................................................................." + "<br>" );
}
对于其他的学生信息增、删、改、查功能不在一一赘述,代码部分与上述功能代码相似。
项目链接请点击:Student_Card_System
标签:drive ext nts 查看 ret end 代码 app 部分
原文地址:https://www.cnblogs.com/yichaoShare/p/10300730.html