out.jsp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <%@ page language="java" contentType="text/html; charset=UTF-8"
  2. pageEncoding="UTF-8" import="java.sql.*"%>
  3. <!DOCTYPE html>
  4. <html>
  5. <head>
  6. <meta charset="UTF-8">
  7. <title>Insert title here</title>
  8. <style type="text/css">
  9. tr:nth-child(2n){ background: #f3f3f3;}
  10. table{width:650px;border:2px;line-height:25px}
  11. .button{margin-top:20px;margin-left:90px}
  12. a{padding-left:20px;}
  13. button{border-radius:10px;height:30px;color:white;background-color:#5ACDCD;border:1px solid #5ACDCD;}
  14. </style>
  15. </head>
  16. <body>
  17. <table border="1" cellspacing="0" cellpadding="1">
  18. <tr>
  19. <th align="center">user</th>
  20. <th align="center">name</th>
  21. <th align="center">password</th>
  22. <th align="center">sex</th>
  23. <th align="center">national</th>
  24. <th align="center">telephone</th>
  25. <th align="center">age</th>
  26. </tr>
  27. <%
  28. try{
  29. Class.forName("com.mysql.jdbc.Driver");
  30. String url="jdbc:mysql://localhost:3306/edu?"+"useUnicode=true&characterEncoding=utf-8";
  31. String user="root";
  32. String password="1009";
  33. Connection con=DriverManager.getConnection(url,user,password);
  34. Statement stmt=con.createStatement();
  35. ResultSet rs=stmt.executeQuery("select * from student");
  36. while(rs.next()){
  37. %>
  38. <tr>
  39. <td align="center"><%=rs.getString("user") %></td>
  40. <td align="center"><%=rs.getString("name") %></td>
  41. <td align="center"><%=rs.getString("password") %></td>
  42. <td align="center"><%=rs.getString("sex") %></td>
  43. <td align="center"><%=rs.getString("national") %></td>
  44. <td align="center"><%=rs.getString("telephone") %></td>
  45. <td align="center"><%=rs.getString("age") %></td>
  46. </tr>
  47. <%
  48. }
  49. rs.close();
  50. stmt.close();
  51. con.close();
  52. }catch(Exception e){
  53. e.printStackTrace();
  54. }
  55. %>
  56. </table>
  57. <div class="button">
  58. <a href="http://localhost:8080/JDBC/stu.jsp"><button>添加数据</button></a>
  59. <a href="student.pdf"><button>导出pdf文件</button></a>
  60. <a href="student.xls"><button>导出Excel文件</button></a>
  61. <a href="#"><button>Excel导入数据库</button></a>
  62. </div>
  63. </body>
  64. </html>