第七周作业
<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.DAO; 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; } }
package domain; public class Doctor { private int id; private String name; private int experience; private String phone; private String profession; private String status; private String username; private String password; public Doctor() { } public Doctor(int id, String name, int experience, String phone, String profession, String status, String username, String password) { this.id = id; this.name = name; this.experience = experience; this.phone = phone; this.profession = profession; this.status = status; this.username = username; this.password = password; } public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getExperience() { return experience; } public void setExperience(int experience) { this.experience = experience; } public String getPhone() { return phone; } public void setPhone(String phone) { this.phone = phone; } public String getProfession() { return profession; } public void setProfession(String profession) { this.profession = profession; } public String getStatus() { return status; } public void setStatus(String status) { this.status = status; } public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } @Override public String toString() { return "Doctor{" + "id=" + id + ", name='" + name + '\'' + ", experience=" + experience + ", phone=" + phone + ", profession='" + profession + '\'' + ", status='" + status + '\'' + '}'; } }