注册功能_邮件激活_点击激活分析、 邮件超链接激活代码实现
注册功能_邮件激活_点击激活分析
分析图解:
设置激活码
user.setCode(UuidUtil.getUuid());
// 设置激活状态
user.setStatus("N");
// 保存用户信息
userDao.save(user);
// 激活邮箱发送,邮件正文
String content = "<a heft=‘http://localhost/travel/activeUserServlet?code="+user.getCode()+">点击激活【黑马旅游网】</a>";
MailUtils.sendMail(user.getEmail(),content,"激活邮件");
return true;
}
}
邮件超链接激活代码实现
ActiveUserServlet
UserService active
UserDao findByCode updeateStatus
@WebServlet("/activeUserServlet")
public class ActiveUserServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
this.doPost(req, resp);
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
// 获取激活码
String code = req.getParameter("code");
if (code!=null){
// 调用servlet完成激活
UserServlce servlce = new UserServlceImpl();
boolean b = servlce.active(code);
// 判断标记
String msg = null;
if (b){
msg="激活成功,请<a href='login.html'>登录</a>";
}else{
msg="激活失败,请联系管理员";
}
resp.setContentType("text/html;charset=utf-8");
resp.getWriter().write(msg);
}
}
}
boolean active(String code);
}
// 激活
@Override
public boolean active(String code) {
return false;
}