public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
req.setCharacterEncoding("UTF-8");
// res.setContentType("text/html; charset=UTF-8");
// String username = req.getParameter("username");
// String password = req.getParameter("password");
// String email = req.getParameter("email");
Map<String, String[]> properties = req.getParameterMap();
Users user = new Users();
try {
BeanUtils.populate(user, properties);
} catch (IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
}
//现在这个位置 user对象已经封装好了
//手动封装uid----uuid---随机不重复的字符串32位--java代码生成后是36位
user.setUid(30);
//3、将参数传递给一个业务操作方法
try {
Adduser(user);
} catch (SQLException e) {
e.printStackTrace();
}
//4、认为注册成功跳转到登录页面
res.sendRedirect(req.getContextPath()+"/login.html");
}
public void Adduser(Users user) throws SQLException {
QueryRunner runner = new QueryRunner(DBUtils.getDataSource());
String sql = "insert into users values(?,?,?,?)";
runner.update(sql,user.getUid(),user.getPname(),user.getPassword(),user.getEmail());
}
throws ServletException, IOException {
req.setCharacterEncoding("UTF-8");
// res.setContentType("text/html; charset=UTF-8");
// String username = req.getParameter("username");
// String password = req.getParameter("password");
// String email = req.getParameter("email");
Map<String, String[]> properties = req.getParameterMap();
Users user = new Users();
try {
BeanUtils.populate(user, properties);
} catch (IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
}
//现在这个位置 user对象已经封装好了
//手动封装uid----uuid---随机不重复的字符串32位--java代码生成后是36位
user.setUid(30);
//3、将参数传递给一个业务操作方法
try {
Adduser(user);
} catch (SQLException e) {
e.printStackTrace();
}
//4、认为注册成功跳转到登录页面
res.sendRedirect(req.getContextPath()+"/login.html");
}
public void Adduser(Users user) throws SQLException {
QueryRunner runner = new QueryRunner(DBUtils.getDataSource());
String sql = "insert into users values(?,?,?,?)";
runner.update(sql,user.getUid(),user.getPname(),user.getPassword(),user.getEmail());
}