//更删改查 index
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <title>注册页面</title> </head> <body> <form action="home.jsp" method="post"> <input type="text" name="username"><br> <input type="text" name="password"><br> <button type="submit">提交</button> </form> </body> </html>//home
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>Title</title> </head> <body> <% //加载数据库驱动 Class.forName("com.mysql.jdbc.Driver" ) ; //建立数据库连接 String url="jdbc:mysql://localhost:3306/whd";//数据库链接地址 Connection connection= DriverManager.getConnection(url,"root","root");//第一个数据库用户名 第二个密码 String sql="select * from whd where username=? and password=?";//在PreparedStatement中使用?代替实际参数 PreparedStatement ps =connection.prepareStatement(sql); ps.setString(1,request.getParameter("username")); ps.setString(2,request.getParameter("password")); ResultSet rs =ps.executeQuery(); while(rs.next()) { out.print(rs.getString("username") + "-" + rs.getString(3) + "<br>"); } %> </body> </htm