JSP学生信息管理系统设计

前端之家收集整理的这篇文章主要介绍了JSP学生信息管理系统设计前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

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

新建学生信息数据库

1.添加记录模块

  1. <%@ page contentType="text/html" pageEncoding="UTF-8"%>
  2.  
  3. <html>
  4. <head>
  5. <title>添加新学生</title>
  6. </head>
  7.  
  8. <body>
  9. <form action="stuinsert2.jsp" method="post">
  10. <table border="0" width="238" heigth="252">
  11. <tr><td>学号:</td><td><input type="text" name="id"></td></tr>
  12. <tr><td>姓名</td><td><input type="text" name="name"></td></tr>
  13. <tr><td>性别</td><td><input type="text" name="sex"></td></tr>
  14. <tr><td>年龄</td><td><input type="text" name="age"></td></tr>
  15. <tr><td>专业</td><td><input type="text" name="sdept"></td></tr>
  16. <tr align="center">
  17. <td colspan="2">
  18. <input type="submit" value="提交">   
  19. <input type="reset" value="取消">
  20. </td>
  21. </tr>
  22. </table>
  23. </form>
  24. </body>
  25. </html>
  26.  
  1. <%@ page language="java" import="java.sql.*" pageEncoding="UTF-8"%>
  2. <html>
  3. <head>
  4. <title>添加学生处理程序</title>
  5. </head>
  6. <body>
  7. <% Class.forName("com.microsoft.sqlserver.jdbc.sqlServerDriver");
  8. String url="jdbc:sqlserver://localhost:1433; DatabaseName=p";
  9. String user="sa";
  10. String password="123456";
  11. Connection conn=DriverManager.getConnection(url,user,password);
  12. request.setCharacterEncoding("UTF-8");
  13. String id=request.getParameter("id");
  14. String name=request.getParameter("name");
  15. String sex=request.getParameter("sex");
  16. int age=Integer.parseInt(request.getParameter("age"));
  17. String sdept=request.getParameter("sdept");
  18. String sql=String.format("select * from student where Sno=%s",id);
  19. Statement stmt=conn.createStatement();
  20. PreparedStatement pstmt;
  21. ResultSet rs=stmt.executeQuery(sql);
  22. if(!(rs.next())){
  23. pstmt=conn.prepareStatement("insert into Student values(?,?,?)");
  24. pstmt.setString(1,id);
  25. pstmt.setString(2,name);
  26. pstmt.setString(3,sex);
  27. pstmt.setInt(4,age);
  28. pstmt.setString(5,sdept);
  29. pstmt.executeUpdate();
  30. out.print("添加成功");
  31. %>
  32. <a href="stuinsert.jsp" rel="external nofollow" rel="external nofollow" >返回菜单</a><br>
  33. <a href="main.jsp" rel="external nofollow" ></a>
  34. <%}else{
  35. out.println("该学号已存在");%>
  36. <a href="stuinsert.jsp" rel="external nofollow" rel="external nofollow" >重新添加</a>
  37. <%}%>
  38. </body>
  39. </html>

2.查询(all)模块

  1. <%@ page language="java" import="java.sql.*" pageEncoding="UTF-8"%>
  2. <%@ page import="javax.sql.*" %>
  3. <%@ page import="javax.naming.*" %>
  4. <html>
  5. <head>
  6. <title>信息查看页面</title>
  7. </head>
  8. <body>
  9. <center>
  10. <% DataSource ds=null;
  11. InitialContext ctx=new InitialContext();
  12. ds=(DataSource)ctx.lookup("java:comp/env/jdbc/sqlserver");
  13. Connection conn=ds.getConnection();
  14. PreparedStatement pstmt=conn.prepareStatement("select * from Student");
  15. ResultSet rs=pstmt.executeQuery();
  16. %>
  17. <table border="2" bgcolor="ccceee" width="650">
  18. <tr bgcolor="CCCCCC" align="center">
  19. <td>记录条数</td><td>学号</td><td>姓名</td>
  20. <td>性别</td><td>年龄</td><td>专业</td>
  21. </tr>
  22. <%
  23. while(rs.next()){
  24. %>
  25. <tr align="center">
  26. <td><%=rs.getRow()%></td>
  27. <td><%=rs.getString(1)%></td>
  28. <td><%=rs.getString(2)%></td>
  29. <td><%=rs.getString(3)%></td>
  30. <td><%=rs.getString(4)%></td>
  31. <td><%=rs.getString(5)%></td>
  32. </tr>
  33. <%}%>
  34. </center>
  35. <%if(rs!=null){rs.close();}
  36. if(pstmt!=null){pstmt.close();}
  37. if(conn!=null){conn.close();}
  38. %>
  39. </table>
  40. </body>
  41. </html>

条件查询模块

  1. <%@ page language="java" pageEncoding="UTF-8"%>
  2. <html>
  3. <head>
  4. <title>My JSP 'stufind2.jsp' starting page</title>
  5. </head>
  6. <body>
  7. 请选择查询条件<hr width="100%" size="3">
  8. <form action="stufind3.jsp" method="post">
  9. 性别<input type="radio" value="男" name="sex" checked="checked">
  10. <input type="radio" value="女" name="sex">
  11. 年龄范围:<p>  
  12. 最小:<input type="text" name="a1"><br><br> 
  13. 最大:<input type="text" name="a2"><p>
  14. <input type="submit" value="提交">
  15. <input type="reset" value="取消">
  16. </form>
  17. </body>
  18. </html>
  1. <%@ page contentType="text/html" import="java.sql.*" pageEncoding="UTF-8"%>
  2. <html>
  3. <head>
  4. <title>条件查询处理页面</title>
  5. </head>
  6. <body>
  7. <center>
  8. <%Class.forName("com.microsoft.sqlserver.jdbc.sqlServerDriver");
  9. String user="sa";
  10. String password="123456";
  11. String url="jdbc:sqlserver://localhost:1433;DatabaseName=p";
  12. Connection conn=DriverManager.getConnection(url,password);
  13. request.setCharacterEncoding("UTF-8");
  14. String sex=request.getParameter("sex");
  15. int age1=Integer.parseInt(request.getParameter("a1"));
  16. int age2=Integer.parseInt(request.getParameter("a2"));
  17. String sql="select * from Student where Ssex=? and Sage>=? and Sage<=?";
  18. PreparedStatement pstmt=conn.prepareStatement(sql);
  19. pstmt.setString(1,sex);
  20. pstmt.setInt(2,age1);
  21. pstmt.setInt(3,age2);
  22. ResultSet rs=pstmt.executeQuery();
  23. %>
  24. <table border="2" bgcolor="ccceee" width="650">
  25. <tr bgcolcor="CCCCCC" align="center">
  26. <td>记录条数</td><td>学号</td><td>姓名</td>
  27. <td>性别</td><td>年龄</td><td>专业</td>
  28. </tr>
  29. <%while(rs.next()){ %>
  30. <tr align="center">
  31. <td><%=rs.getRow()%></td>
  32. <td><%=rs.getString(1)%></td>
  33. <td><%=rs.getString(2)%></td>
  34. <td><%=rs.getString(3)%></td>
  35. <td><%=rs.getString(4)%></td>
  36. <td><%=rs.getString(5)%></td>
  37. </tr>
  38. <%}%>
  39. </table>
  40. <%if(rs!=null){rs.close();}
  41. if(pstmt!=null){pstmt.close();}
  42. if(conn!=null){conn.close();}
  43. %>
  44. </center>
  45. </body>
  46. </html>

3.修改模块

  1. <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
  2. <html>
  3. <head>
  4. <title>修改提交页面</title>
  5. </head>
  6. <body>
  7. <center>
  8. 请选择修改记录所满足的条件
  9. <form action="stuupdate2.jsp" method="post">
  10. 姓名: <input type="text" name="name"><br><br>
  11. 性别: 男<input type="radio" value="男" name="sex">
  12. <input type="radio" value="女" name="sex"><br><br>
  13. <input type="submit" value="提交">   
  14. <input type="reset" value="取消">
  15. </form>
  16. </center>
  17. </body>
  18. </html>
  1. <%@ page contentType="text/html" import="java.sql.*" pageEncoding="UTF-8"%>
  2. <html>
  3. <head>
  4. <title>修改编辑页面</title>
  5. </head>
  6. <body>
  7. <% Class.forName("com.microsoft.sqlserver.jdbc.sqlServerDriver");
  8. String user="sa";
  9. String password="123456";
  10. String url="jdbc:sqlserver://localhost:1433;DatabaseName=p";
  11. Connection conn=DriverManager.getConnection(url,password);
  12. request.setCharacterEncoding("UTF-8");
  13. String name=request.getParameter("name");
  14. String sex=request.getParameter("sex");
  15. session.setAttribute("sex",sex);
  16. session.setAttribute("name",name);
  17. String sql="select * from Student where Ssex=? and Sname=?";
  18. PreparedStatement pstmt=conn.prepareStatement(sql);
  19. pstmt.setString(1,sex);
  20. pstmt.setString(2,name);
  21. ResultSet rs=pstmt.executeQuery();
  22. if(rs.next()){
  23. String id=rs.getString("Sno");
  24. String name2=rs.getString("Sname");
  25. String sex2=rs.getString("Ssex");
  26. int age=rs.getInt("Sage");
  27. String sdept=rs.getString("Sdept");
  28. if(pstmt!=null){pstmt.close();}
  29. if(rs!=null){rs.close();}
  30. if(conn!=null){conn.close();}
  31. %>
  32. <form action="stuupdate3.jsp" method="post">
  33. <table border="0" width="238" height="252">
  34. <tr><td>学号:</td><td><input type="text" name="id" value=<%=id%>></td></tr>
  35. <tr><td>姓名:</td><td><input type="text" name="name2" value=<%=name2%>></td></tr>
  36. <tr><td>性别:</td><td><input type="text" name="sex2" value=<%=sex2%>></td></tr>
  37. <tr><td>年龄:</td><td><input type="text" name="age" value=<%=age%>></td></tr>
  38. <tr><td>专业:</td><td><input type="text" name="sdept" value=<%=sdept%>></td></tr>
  39. <tr align="center">
  40. <td colspan="2">
  41. <input type="submit" value="提交">   
  42. <input type="reset" value="取消">
  43. </td>
  44. </tr>
  45. </table>
  46. </form>
  47. <%}
  48. else{%>
  49. 没有找到合适条件的记录!!<%
  50. if(rs!=null){rs.close();}
  51. if(pstmt!=null){pstmt.close();}
  52. if(conn!=null){conn.close();}
  53. }%>
  54. </body>
  55. </html>
  1. <%@ page language="java" import="java.sql.*" pageEncoding="UTF-8"%>
  2. <html>
  3. <head>
  4. <title>修改后重写页面</title>
  5. </head>
  6. <body>
  7. <% Class.forName("com.microsoft.sqlserver.jdbc.sqlServerDriver");
  8. String url="jdbc:sqlserver://localhost:1433; DatabaseName=p";
  9. String user="sa";
  10. String password="123456";
  11. Connection conn=DriverManager.getConnection(url,password);
  12. String sql="update Student set Sno=?,Sname=?,Ssex=?,Sage=?,Sdept=? where Sname=? and Ssex=?";
  13. PreparedStatement pstmt=conn.prepareStatement(sql);
  14. request.setCharacterEncoding("UTF-8");
  15. String id=request.getParameter("id");
  16. String name2=request.getParameter("name2");
  17. String sex2=request.getParameter("sex2");
  18. int age=Integer.parseInt(request.getParameter("age"));
  19. String sdept=request.getParameter("sdept");
  20. String name=(String)session.getAttribute("name");
  21. String sex=(String)session.getAttribute("sex");
  22. pstmt.setString(1,id); pstmt.setString(2,name2);
  23. pstmt.setString(3,sex2); pstmt.setInt(4,sdept); pstmt.setString(6,name);
  24. pstmt.setString(7,sex);
  25. int n=pstmt.executeUpdate();
  26. if(n>=1){%>重写数据库操作成功!<br><%}
  27. else{%>重写数据库操作失败!<br><%}
  28. if(pstmt!=null){pstmt.close();}
  29. if(conn!=null){conn.close();}
  30. %>
  31. </body>
  32. </html>

4.删除记录模块

  1. <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
  2. <html>
  3. <head>
  4. <title>条件删除提交页面</title>
  5. </head>
  6. <body>
  7. 请选择删除记录条件<<hr width="100%" size="3">
  8. <form action="studelete2.jsp" method="post">
  9. 姓名:<input type="text" name="name"><br><br>
  10. 性别:男<input type="radio" value="男" name="sex">
  11. <input type="radio" value="女" name="sex"><br><br>
  12. 年龄范围:<br><p>
  13. 最小:<input type="text" name="a1"><br>
  14. 最大:<input type="text" name="a2">
  15. </p>
  16. <input type="submit" value="提交">
  17. <input type="reset" value="取消">
  18.  
  19. </form>
  20. </body>
  21. </html>
  22.  
  1. <%@ page language="java" import="java.sql.*" pageEncoding="UTF-8"%>
  2. <html>
  3. <head>
  4. <title>条件删除处理页面</title>
  5. </head>
  6. <body>
  7. <% Class.forName("com.microsoft.sqlserver.jdbc.sqlServerDriver");
  8. String user="sa";
  9. String password="123456";
  10. String url="jdbc:sqlserver://localhost:1433;DatabaseName=p";
  11. Connection conn=DriverManager.getConnection(url,password);
  12. request.setCharacterEncoding("UTF-8");
  13. String name=request.getParameter("name");
  14. String sex=request.getParameter("sex");
  15. String ag1=request.getParameter("a1");
  16. String ag2=request.getParameter("a2");
  17. int a3,a4;
  18. String sql="delete from Student where Sname=? and Ssex=? and Sage>=? and Sage<=?";
  19. PreparedStatement pstmt=conn.prepareStatement(sql);
  20. if(!name.equals("")) pstmt.setString(1,name);
  21. if(sex!=null) pstmt.setString(2,sex);
  22. if(!ag1.equals("")){a3=Integer.parseInt(ag1); pstmt.setInt(3,a3);}
  23. if(!ag2.equals("")){a4=Integer.parseInt(ag2); pstmt.setInt(4,a4);}
  24. int n=pstmt.executeUpdate();
  25. if(n==1){%>数据删除成功<br><%}
  26. else{%>数据删除失败!<br><%}
  27. if(pstmt!=null){pstmt.close();}
  28. if(conn!=null){conn.close();}
  29. %>
  30. </body>
  31. </html>
  32.  

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

猜你在找的Jsp相关文章