第七周jsp
<form action="dologin.jsp" method="post"> 用户名:<input id="username" type="text" name="username"/><br/> 密码:<input id="password" type="password" name="password"/><br/> <%-- 验证码:<input type="text" name="inputVcode"/><img src="/WebProject_war_exploded/createCode"><br/>--%> <input type="submit" value="注册"> </form>
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>Title</title> </head> <body> <% String uname = request.getParameter("username"); String upwd = request.getParameter("password"); dlBean dlbean = new dlBean(); dlbean.setUname(uname); dlbean.setUpwd(upwd); dlDAO dlDAO = new dlDAO(); Integer res = dlDAO.insert(dlbean); if (res>0){ response.sendRedirect("success.jsp"); } %>
package com.dx.entity; public class dlBean { private int uid; private String uname; private String upwd; public dlBean() { } public dlBean(int uid, String uname, String upwd) { this.uid = uid; this.uname = uname; this.upwd = upwd; } @Override public String toString() { return "dlBean{" + "uid=" + uid + ", uname='" + uname + '\'' + ", upwd='" + upwd + '\'' + '}'; } public int getUid() { return uid; } public void setUid(int uid) { this.uid = uid; } public String getUname() { return uname; } public void setUname(String uname) { this.uname = uname; } public String getUpwd() { return upwd; } public void setUpwd(String upwd) { this.upwd = upwd; } import com.dx.entity.dlBean; import java.sql.*; public class dlDAO { public int insert(dlBean dlBean) throws ClassNotFoundException, SQLException { Class.forName("com.mysql.jdbc.Driver"); Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/mysql", "root", "root"); PreparedStatement preparedStatement = connection.prepareStatement("insert into dl(uname,upwd)value (?,?)"); preparedStatement.setString(1, dlBean.getUname()); preparedStatement.setString(2, dlBean.getUpwd()); Integer res = preparedStatement.executeUpdate(); return res; } }