①首先注册完以后,进行判断,注册成功的链接到成功页面,注册失败的;链接到失败页面;
②成功的页面中包含邮箱验证 点击其中的链接进行邮箱验证需要把状态码由0变成1;
③调用发邮箱的工具类,发送给刚才注册的邮箱(用A发送给B来进行模拟),里边是包含激活码,根据激活码查出用户进行设置状态,由0变成1
④然后点击邮箱中的链接,链接到一个servlet中,来进行修改状态码操作;
web层
UserService userService=new UserService();
Boolean issuccess = null;
try {
issuccess=userService.isregistersuccess(user);
} catch (SQLException e) {
e.printStackTrace();
}
String email = user.getEmail();
//注册完以后连接到其他页面
if(issuccess){
response.sendRedirect(request.getContextPath()+"/registerSuccess.jsp");
//发送验证邮件
try {
String emailMsg="恭喜您注册成功,请点击下面的连接进行激活账户"
+ "<a href='http://localhost:8080/HeimaShop/active?activeCode="+code+"'>"
+ "http://localhost:8080/HeimaShop/active?activeCode="+code+"</a>";;
//这一共相当于三段字符串进行拼接
MailUtils.sendMail(email,emailMsg);
} catch (MessagingException e) {
e.printStackTrace();
}
}else{
response.sendRedirect(request.getContextPath()+"/registerFail.jsp");
}
service层
public void active(String activeCode) throws SQLException {
UserDao userDao=new UserDao();
userDao.active(activeCode);
}
dao层
public void active(String activeCode) throws SQLException {
QueryRunner queryRunner=new QueryRunner(DataSourceUtils.getDataSource());
String sql="update user set state=? where code=?";
queryRunner.update(sql,1,activeCode);
}