JAVA邮箱验证重要代码

RegServlet类 Post方法 添加如下代码:
if(isRegSuccess){
			//发送激活邮件
	String emailMsg = "恭喜您注册成功,请点击下面的连接进行激活账户"
	+ "<a href='http://localhost:8080/xiangmuming/active?activeCode="
+activeCode+"'>"+"http://localhost:8080/xiangmuming/active?activeCode="+activeCode+"</a>";
		try {
				MailUtils.sendMail(user.getEmail(), emailMsg);
			} catch (AddressException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
			} catch (MessagingException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
			}
				response.sendRedirect(request.getContextPath()+"/registerSuccess.jsp");
		  }else{
			  response.sendRedirect(request.getContextPath()+"/registerFail.jsp");
		  }
UserDao类
// 激活
	public void active(String code) {
		QueryRunner runner = new QueryRunner(DataSourceUtils.getDataSource());
		String sql = "update user set state=? where code=?";
		try {
			runner.update(sql, 1, code);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
UserService类
//激活用户
	public void active(String code){
		userDao.active(code);
	}

4.ActiveServlet类
public class ActiveServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
    
	private UserService userService=new UserService();
	
  
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}


	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String activeCode=request.getParameter("activeCode");
		userService.active(activeCode);
		response.sendRedirect(request.getContextPath()+"/login.jsp");
		
	}

}
以上代码在本人项目中已运行成功,如有不恰当地方请各位大神多多指教


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值