网络编程 
首页 > 网络编程 > 浏览文章

JSP学生信息管理系统设计

(编辑:jimmy 日期: 2024/11/26 浏览:3 次 )

本文实例为大家分享了JSP学生信息管理系统源码,供大家参考,具体内容如下

新建学生信息数据库

1.添加记录模块

<%@ page contentType="text/html" pageEncoding="UTF-8"%>

<html>
 <head> 
 <title>添加新学生</title> 
 </head>

 <body>
 <form action="stuinsert2.jsp" method="post">
 <table border="0" width="238" heigth="252">
 <tr><td>学号:</td><td><input type="text" name="id"></td></tr>
 <tr><td>姓名</td><td><input type="text" name="name"></td></tr>
 <tr><td>性别</td><td><input type="text" name="sex"></td></tr>
 <tr><td>年龄</td><td><input type="text" name="age"></td></tr>
 <tr><td>专业</td><td><input type="text" name="sdept"></td></tr>
 <tr align="center">
 <td colspan="2">
 <input type="submit" value="提交">&nbsp;&nbsp;&nbsp;
 <input type="reset" value="取消">
 </td>
 </tr>
 </table>
 </form>
 </body>
</html>

<%@ page language="java" import="java.sql.*" pageEncoding="UTF-8"%>
<html>
 <head>
 <title>添加学生处理程序</title>
 </head>
 <body>
 <% Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); 
    String url="jdbc:sqlserver://localhost:1433; DatabaseName=p"; 
    String user="sa";
    String password="123456"; 
  Connection conn=DriverManager.getConnection(url,user,password);
  request.setCharacterEncoding("UTF-8");
  String id=request.getParameter("id");
  String name=request.getParameter("name");
  String sex=request.getParameter("sex");
  int age=Integer.parseInt(request.getParameter("age"));
  String sdept=request.getParameter("sdept");
  String sql=String.format("select * from student where Sno=%s",id);
  Statement stmt=conn.createStatement();
  PreparedStatement pstmt;
  ResultSet rs=stmt.executeQuery(sql);
  if(!(rs.next())){
  pstmt=conn.prepareStatement("insert into Student values(");
  pstmt.setString(1,id);
  pstmt.setString(2,name);
  pstmt.setString(3,sex);
  pstmt.setInt(4,age);
  pstmt.setString(5,sdept);
  pstmt.executeUpdate();
  out.print("添加成功");  
  %>
  <a href="stuinsert.jsp" rel="external nofollow" rel="external nofollow" >返回菜单</a><br>
  <a href="main.jsp" rel="external nofollow" ></a>
  <%}else{
  out.println("该学号已存在");%>
  <a href="stuinsert.jsp" rel="external nofollow" rel="external nofollow" >重新添加</a>
  <%}%>
 </body>
</html>

2.查询(all)模块

<%@ page language="java" import="java.sql.*" pageEncoding="UTF-8"%>
<%@ page import="javax.sql.*" %>
<%@ page import="javax.naming.*" %>
<html>
 <head>
 <title>信息查看页面</title>
 </head> 
 <body>
 <center>
 <% DataSource ds=null;
  InitialContext ctx=new InitialContext();
  ds=(DataSource)ctx.lookup("java:comp/env/jdbc/sqlserver");
  Connection conn=ds.getConnection();
  PreparedStatement pstmt=conn.prepareStatement("select * from Student");
  ResultSet rs=pstmt.executeQuery();
 %>   
 <table border="2" bgcolor="ccceee" width="650">
 <tr bgcolor="CCCCCC" align="center">
  <td>记录条数</td><td>学号</td><td>姓名</td>
  <td>性别</td><td>年龄</td><td>专业</td>
 </tr>
 <%
  while(rs.next()){
 %> 
 <tr align="center">
 <td><%=rs.getRow()%></td>
 <td><%=rs.getString(1)%></td>
 <td><%=rs.getString(2)%></td>
 <td><%=rs.getString(3)%></td>
 <td><%=rs.getString(4)%></td>
 <td><%=rs.getString(5)%></td>
 </tr>
 <%}%>
 </center>
 <%if(rs!=null){rs.close();}
  if(pstmt!=null){pstmt.close();}
  if(conn!=null){conn.close();}
  %>
 </table> 
 </body>
</html>

条件查询模块

<%@ page language="java" pageEncoding="UTF-8"%>
<html>
 <head>
 <title>My JSP 'stufind2.jsp' starting page</title>
 </head>
 <body>
 请选择查询条件<hr width="100%" size="3">
 <form action="stufind3.jsp" method="post">
 性别<input type="radio" value="男" name="sex" checked="checked">男
 <input type="radio" value="女" name="sex">女
 年龄范围:<p>&nbsp;&nbsp;
 最小:<input type="text" name="a1"><br><br>&nbsp;
 最大:<input type="text" name="a2"><p>
 <input type="submit" value="提交">
 <input type="reset" value="取消">
 </form>
 </body>
</html>
<%@ page contentType="text/html" import="java.sql.*" pageEncoding="UTF-8"%>
<html>
 <head>
 <title>条件查询处理页面</title>
 </head>
 <body>
 <center>
 <%Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
 String user="sa";
 String password="123456";
 String url="jdbc:sqlserver://localhost:1433;DatabaseName=p";
 Connection conn=DriverManager.getConnection(url,user,password);
 request.setCharacterEncoding("UTF-8");
 String sex=request.getParameter("sex");
 int age1=Integer.parseInt(request.getParameter("a1"));
 int age2=Integer.parseInt(request.getParameter("a2"));
 String sql="select * from Student where Ssex=";
 PreparedStatement pstmt=conn.prepareStatement(sql);
 pstmt.setString(1,sex);
 pstmt.setInt(2,age1);
 pstmt.setInt(3,age2);
 ResultSet rs=pstmt.executeQuery();
 %>
 <table border="2" bgcolor="ccceee" width="650">
 <tr bgcolcor="CCCCCC" align="center">
 <td>记录条数</td><td>学号</td><td>姓名</td>
 <td>性别</td><td>年龄</td><td>专业</td>
 </tr>
 <%while(rs.next()){ %>
 <tr align="center">
 <td><%=rs.getRow()%></td>
 <td><%=rs.getString(1)%></td>
 <td><%=rs.getString(2)%></td>
 <td><%=rs.getString(3)%></td>
 <td><%=rs.getString(4)%></td>
 <td><%=rs.getString(5)%></td>
 </tr>
 <%}%>
 </table>
 <%if(rs!=null){rs.close();}
  if(pstmt!=null){pstmt.close();}
  if(conn!=null){conn.close();}
 %>
 </center>
 </body>
</html>

3.修改模块

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<html>
 <head> 
 <title>修改提交页面</title>
 </head>
 <body>
 <center>
  请选择修改记录所满足的条件
 <form action="stuupdate2.jsp" method="post">
  姓名: <input type="text" name="name"><br><br>
  性别: 男<input type="radio" value="男" name="sex">
      女<input type="radio" value="女" name="sex"><br><br>
  <input type="submit" value="提交">&nbsp;&nbsp;&nbsp;
  <input type="reset" value="取消">
 </form>
 </center>
 </body>
</html>
<%@ page contentType="text/html" import="java.sql.*" pageEncoding="UTF-8"%>
<html>
 <head> 
 <title>修改编辑页面</title>
 </head>
 <body>
 <% Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
  String user="sa";
  String password="123456";
  String url="jdbc:sqlserver://localhost:1433;DatabaseName=p";
  Connection conn=DriverManager.getConnection(url,user,password);
  request.setCharacterEncoding("UTF-8");
  String name=request.getParameter("name");
  String sex=request.getParameter("sex");
  session.setAttribute("sex",sex);
  session.setAttribute("name",name);
  String sql="select * from Student where Ssex=";
  PreparedStatement pstmt=conn.prepareStatement(sql);
  pstmt.setString(1,sex);
  pstmt.setString(2,name);
  ResultSet rs=pstmt.executeQuery();
  if(rs.next()){
  String id=rs.getString("Sno");
  String name2=rs.getString("Sname");
  String sex2=rs.getString("Ssex");
  int age=rs.getInt("Sage");
  String sdept=rs.getString("Sdept");
  if(pstmt!=null){pstmt.close();}
  if(rs!=null){rs.close();}
  if(conn!=null){conn.close();}
  %>
  <form action="stuupdate3.jsp" method="post">
  <table border="0" width="238" height="252">
  <tr><td>学号:</td><td><input type="text" name="id" value=<%=id%</td></tr>
  <tr><td>姓名:</td><td><input type="text" name="name2" value=<%=name2%</td></tr>
  <tr><td>性别:</td><td><input type="text" name="sex2" value=<%=sex2%</td></tr>
  <tr><td>年龄:</td><td><input type="text" name="age" value=<%=age%</td></tr>
  <tr><td>专业:</td><td><input type="text" name="sdept" value=<%=sdept%</td></tr>
  <tr align="center">
  <td colspan="2">
  <input type="submit" value="提交">&nbsp;&nbsp;&nbsp;
  <input type="reset" value="取消">
  </td>
  </tr>
  </table>
  </form>
  <%}
  else{%>
      没有找到合适条件的记录!!<%
   if(rs!=null){rs.close();}
   if(pstmt!=null){pstmt.close();}
   if(conn!=null){conn.close();}
 }%>
 </body>
</html>
<%@ page language="java" import="java.sql.*" pageEncoding="UTF-8"%>
<html>
 <head> 
 <title>修改后重写页面</title> 
 </head>
 <body>
 <% Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); 
  String url="jdbc:sqlserver://localhost:1433; DatabaseName=p"; 
  String user="sa";
  String password="123456"; 
  Connection conn=DriverManager.getConnection(url,user,password);
  String sql="update Student set Sno=";
  PreparedStatement pstmt=conn.prepareStatement(sql);
  request.setCharacterEncoding("UTF-8");
  String id=request.getParameter("id");
  String name2=request.getParameter("name2");
  String sex2=request.getParameter("sex2");
  int age=Integer.parseInt(request.getParameter("age"));
  String sdept=request.getParameter("sdept");
  String name=(String)session.getAttribute("name");
  String sex=(String)session.getAttribute("sex");
  pstmt.setString(1,id); pstmt.setString(2,name2);
  pstmt.setString(3,sex2); pstmt.setInt(4,age);
  pstmt.setString(5,sdept); pstmt.setString(6,name);
  pstmt.setString(7,sex);
  int n=pstmt.executeUpdate();
  if(n>=1){%>重写数据库操作成功!<br><%}
  else{%>重写数据库操作失败!<br><%}
  if(pstmt!=null){pstmt.close();}
  if(conn!=null){conn.close();}
 %>
 </body>
</html>

4.删除记录模块

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<html>
 <head> 
 <title>条件删除提交页面</title>
 </head>
 <body>
  请选择删除记录条件<<hr width="100%" size="3">
  <form action="studelete2.jsp" method="post">
  姓名:<input type="text" name="name"><br><br>
  性别:男<input type="radio" value="男" name="sex">
  女<input type="radio" value="女" name="sex"><br><br>
  年龄范围:<br><p>
  最小:<input type="text" name="a1"><br>
  最大:<input type="text" name="a2">
  </p>
  <input type="submit" value="提交">
  <input type="reset" value="取消">

  </form>
 </body>
</html>

<%@ page language="java" import="java.sql.*" pageEncoding="UTF-8"%>
<html>
 <head> 
 <title>条件删除处理页面</title>
 </head> 
 <body>
 <% Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
  String user="sa";
  String password="123456";
  String url="jdbc:sqlserver://localhost:1433;DatabaseName=p";
  Connection conn=DriverManager.getConnection(url,user,password);
  request.setCharacterEncoding("UTF-8");
  String name=request.getParameter("name");
  String sex=request.getParameter("sex");
  String ag1=request.getParameter("a1");
  String ag2=request.getParameter("a2");
  int a3,a4;
  String sql="delete from Student where Sname=";
  PreparedStatement pstmt=conn.prepareStatement(sql);
  if(!name.equals("")) pstmt.setString(1,name);
  if(sex!=null) pstmt.setString(2,sex);
  if(!ag1.equals("")){a3=Integer.parseInt(ag1); pstmt.setInt(3,a3);}
  if(!ag2.equals("")){a4=Integer.parseInt(ag2); pstmt.setInt(4,a4);}
  int n=pstmt.executeUpdate();
  if(n==1){%>数据删除成功<br><%}
  else{%>数据删除失败!<br><%}
  if(pstmt!=null){pstmt.close();}
  if(conn!=null){conn.close();}
 %>
 </body>
</html>

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。

上一篇:web下载文件和跳转的方法
下一篇:秒杀系统Web层设计的实现方法
一句话新闻
一文看懂荣耀MagicBook Pro 16
荣耀猎人回归!七大亮点看懂不只是轻薄本,更是游戏本的MagicBook Pro 16.
人们对于笔记本电脑有一个固有印象:要么轻薄但性能一般,要么性能强劲但笨重臃肿。然而,今年荣耀新推出的MagicBook Pro 16刷新了人们的认知——发布会上,荣耀宣布猎人游戏本正式回归,称其继承了荣耀 HUNTER 基因,并自信地为其打出“轻薄本,更是游戏本”的口号。
众所周知,寻求轻薄本的用户普遍更看重便携性、外观造型、静谧性和打字办公等用机体验,而寻求游戏本的用户则普遍更看重硬件配置、性能释放等硬核指标。把两个看似难以相干的产品融合到一起,我们不禁对它产生了强烈的好奇:作为代表荣耀猎人游戏本的跨界新物种,它究竟做了哪些平衡以兼顾不同人群的各类需求呢?
友情链接:杰晶网络 DDR爱好者之家 南强小屋 黑松山资源网 白云城资源网 网站地图 SiteMap