<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ page import="java.sql.*"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>查询学生信息</title> </head> <body> <% String a = request.getParameter("id"); String b = request.getParameter("class"); String URL = "jdbc:mysql://localhost:3306/SCORE"; String USERNAME = "root"; String PWD = "123456"; //jsp就是在html中嵌套的java代码,因此java代码可以写在jsp中(《%%》) PreparedStatement pstmt = null; ResultSet rs = null; Connection connection = null; try { // a.导入驱动,加载具体驱动类 Class.forName("com.mysql.cj.jdbc.Driver");//注册// 加载具体的驱动类 // b.与数据库建立链接 connection = DriverManager.getConnection(URL, USERNAME, PWD); String sql = "select * from information where 编号 like ? and 班级 like ?"; pstmt = connection.prepareStatement(sql); pstmt.setString(1, "%" + a + "%"); pstmt.setString(2, "%" + b + "%"); rs = pstmt.executeQuery();// 反回值,增删改了几条数据增删改用update %> <table align="center" border="1px"> <tr> <td align="center">姓名</td> <td align="center">编号</td> <td align="center">年级</td> <td align="center">班级</td> <td align="center">学科1</td> <td align="center">学科2</td> <td align="center">学科3</td> </tr> <% while (rs.next()) { String hubie = rs.getString("姓名"); String shoujiaoyuchengdu = rs.getString("编号"); String zhufang = rs.getString("年级"); String mianji = rs.getString("班级"); String fangshu = rs.getString("学科1"); String xingming = rs.getString("学科2"); String shenfen = rs.getString("学科3"); %> <tr> <td align="center"> <% out.print(hubie); %> </td> <td align="center"> <% out.print(shoujiaoyuchengdu); %> </td> <td align="center"> <% out.print(zhufang); %> </td> <td align="center"> <% out.print(mianji); %> </td> <td align="center"> <% out.print(fangshu); %> </td> <td align="center"> <% out.print(xingming); %> </td> <td align="center"> <% out.print(shenfen); %> </td> </tr> <% } %> </table> <% } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (SQLException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } finally { // 关闭数据库 try {//先开的后关 if (rs != null) rs.close(); if (pstmt != null) pstmt.close();// 对象.方法 if (connection != null) connection.close(); } catch (SQLException e) { e.printStackTrace(); } } %> </body> </html>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>用户登录</title> </head> <body> <form action="Servlet"> <table align="center" method="get" border="1px"> <tr> <td>登录</td> <td><select name="identity"> <option value="学生">学生</option> <option value="教师">教师</option> <option value="管理员">管理员</option> </select></td> </tr> <tr> <td>编号</td> <td><input type="text" name="id" /></td> </tr> <tr> <td>密码</td> <td><input type="password" name="pwd" placeholder="请输入密码" /></td> </tr> <tr align="center"> <td colspan="2"><input type="submit" value="登录" /> <input type="reset" value="重置" /></td> </tr> </table> </form> </body> </html>
标签:总结,学科,登录,每日,5.30,编号 From: https://www.cnblogs.com/louwangshayu/p/17444636.html