谁知道怎么注册instring我的注册扣扣不要手机号的和扣扣邮箱都注册不了

1207人阅读
J2EE(44)
修改信息:
package com.ethan.accountactivate.
import java.io.IOE
import java.io.PrintW
import javax.servlet.ServletE
import javax.servlet.http.HttpS
import javax.servlet.http.HttpServletR
import javax.servlet.http.HttpServletR
public class UpdateAccountUI extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.getRequestDispatcher(&/WEB-INF/pages/updateAccountUI.jsp&).forward(request, response);
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
package com.ethan.accountactivate.
import java.io.IOE
import java.io.PrintW
import java.util.UUID;
import javax.servlet.ServletE
import javax.servlet.http.HttpS
import javax.servlet.http.HttpServletR
import javax.servlet.http.HttpServletR
import com.ethan.accountactivate.domain.U
import com.ethan.accountactivate.utils.EmailU
public class UpdateAccount extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String email = request.getParameter(&email&);
User user = (User) request.getSession().getAttribute(&user&);
user.setEmail(email);
//冻结账户
user.setActivated(false);
user.setRandKey(UUID.randomUUID().toString());
//发送邮件
EmailUtil.sendMail(user);
} catch (Exception e) {
e.printStackTrace();
request.getRequestDispatcher(&WEB-INF/pages/login.jsp&).forward(request, response);
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
pass.dat文件在com.ethan.accountactivate.utils包下边
package com.ethan.accountactivate.
import java.io.IOE
import java.io.PrintW
import javax.servlet.ServletE
import javax.servlet.http.HttpS
import javax.servlet.http.HttpServletR
import javax.servlet.http.HttpServletR
import com.ethan.accountactivate.domain.U
import com.ethan.accountactivate.utils.EmailU
public class RenewActivate extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
User user = (User) request.getSession().getAttribute(&user&);
EmailUtil.sendMail(user);
//此处可以转到页面,提示发送成功,根据提供的邮箱后缀,判断是哪个邮箱服务器,给出相应的邮箱连接,让用户进入邮箱去激活
request.getRequestDispatcher(&/WEB-INF/pages/loginUI.jsp&).forward(request, response);
} catch (Exception e) {
e.printStackTrace();
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
com.ethan.accountactivate.utils
pass.dat文件在com.ethan.accountactivate.utils包下边,里边是我的126邮箱密码
package com.ethan.accountactivate.
import java.security.MessageD
import javax.servlet.ServletR
import com.ethan.accountactivate.domain.U
public class AccountActivateUtil {
/*//假的邮箱
public static String generateActivateLink(int userId) {
//只要知道userId,假邮箱就可以激活。直接输入这个连接
return &http://localhost:8080/accountActivate/ActivateAccount?id=&+userId;
//便于维护,只用改一个地方
private static final String checkCodeName = &checkCode&;
public static String generateActivateLink(User user) {
//只要知道userId,假邮箱就可以激活。直接输入这个连接
String link = &http://localhost:8080/accountActivate/ActivateAccount?id=&+user.getId()+&&&+checkCodeName+&=&+generateCheckcode(user);
System.out.println(link);
public static boolean verifyCheckcode(ServletRequest request,User user) {
String checkcode = request.getParameter(checkCodeName);
return checkcode.equals(generateCheckcode(user));
private static String generateCheckcode(User user) {
String password = user.getPassword();
String randKey = user.getRandKey();
System.out.println(randKey);
return md5(password+randKey);
private static String md5(String string) {
char[] codes = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
StringBuilder sb = new StringBuilder();
MessageDigest md = MessageDigest.getInstance(&md5&);
byte[] digest = md.digest(string.getBytes());
for(int i=0;i&digest.i++) {
sb.append(codes[(digest[i]&&4)&0x0f]);
sb.append(codes[digest[i]&0x0f]);
} catch (Exception e) {
e.printStackTrace();
return sb.toString();
package com.ethan.accountactivate.
import java.io.BufferedR
import java.io.IOE
import java.io.InputS
import java.io.InputStreamR
import java.util.D
import java.util.P
import javax.mail.M
import javax.mail.PasswordA
import javax.mail.S
import javax.mail.T
import javax.mail.internet.InternetA
import javax.mail.internet.MimeM
import com.ethan.accountactivate.domain.U
public class EmailUtil {
public static void sendMail(User user) throws Exception {
Properties props = new Properties();
props.setProperty(&mail.transport.protocol&, &smtp&);
//发送方一定要是126的邮箱
props.setProperty(&mail.host&, &&);
//需要传递用户名和密码
props.setProperty(&mail.smtp.auth&, &true&);
Session session = Session.getInstance(props, new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
InputStream ips = EmailUtil.class.getResourceAsStream(&pass.dat&);
BufferedReader bis = new BufferedReader(new InputStreamReader(ips));
String pass = bis.readLine();
System.out.println(pass);
bis.close();
//126邮箱作为发送方
return new PasswordAuthentication(&&,pass);
} catch(IOException e) {
e.printStackTrace();
Message msg = new MimeMessage(session);
//发送人 MimeUtility.encodeText()可以用来编码
msg.setFrom(InternetAddress.parse(&&)[0]);
//发送内容
msg.setSubject(&ethan 为您发送的激活连接&);
msg.setRecipient(Message.RecipientType.TO, new InternetAddress(user.getEmail()));
//发件日期
msg.setSentDate(new Date());
msg.setContent(&&a href='&+AccountActivateUtil.generateActivateLink(user)+&'&单击此处激活帐号&/a&&,&text/charset=utf-8&);
Transport.send(msg);
下边是jsp页面:
/accountActivate/WebRoot/WEB-INF/pages
registerUserUI.jsp
&%@ page language=&java& import=&java.util.*& pageEncoding=&UTF-8&%&
String path = request.getContextPath();
String basePath = request.getScheme()+&://&+request.getServerName()+&:&+request.getServerPort()+path+&/&;
&!DOCTYPE HTML PUBLIC &-//W3C//DTD HTML 4.01 Transitional//EN&&
&base href=&&%=basePath%&&&
&title&My JSP 'registerUserUI.jsp' starting page&/title&
&meta http-equiv=&pragma& content=&no-cache&&
&meta http-equiv=&cache-control& content=&no-cache&&
&meta http-equiv=&expires& content=&0&&
&meta http-equiv=&keywords& content=&keyword1,keyword2,keyword3&&
&meta http-equiv=&description& content=&This is my page&&
&link rel=&stylesheet& type=&text/css& href=&styles.css&&
&style type=&text/css&&
&form action=&${pageContext.request.contextPath }/RegisterUser& method=&post&&
用户名:&input type=&text& name=&userName& value=&${param.userName }&&&span class=&error&&${errors.userName}&/span&&br/&
密码:&input type=&password& name=&password& value=&${param.password }&&&span class=&error&&${errors.password}&/span&&br/&
确认密码:&input type=&password& name=&password2& value=&${param.password2 }&&&span class=&error&&${errors.password2}&/span&&br/&
邮箱地址:&input type=&text& name=&email& value=&${param.email }&&&span class=&error&&${errors.email}&/span&&br/&
&input type=&submit& name=&submit& value=&注册&&&br/&
registerUser.jsp&%@ page language=&java& import=&java.util.*& pageEncoding=&UTF-8&%&
String path = request.getContextPath();
String basePath = request.getScheme()+&://&+request.getServerName()+&:&+request.getServerPort()+path+&/&;
&!DOCTYPE HTML PUBLIC &-//W3C//DTD HTML 4.01 Transitional//EN&&
&base href=&&%=basePath%&&&
&title&My JSP 'registerUser.jsp' starting page&/title&
&meta http-equiv=&pragma& content=&no-cache&&
&meta http-equiv=&cache-control& content=&no-cache&&
&meta http-equiv=&expires& content=&0&&
&meta http-equiv=&keywords& content=&keyword1,keyword2,keyword3&&
&meta http-equiv=&description& content=&This is my page&&
&link rel=&stylesheet& type=&text/css& href=&styles.css&&
注册成功,请收邮件以激活您的帐号。如果email有错误,请修改你的账户信息。&br&
loginUI.jsp
&%@ page language=&java& import=&java.util.*& pageEncoding=&UTF-8&%&
String path = request.getContextPath();
String basePath = request.getScheme()+&://&+request.getServerName()+&:&+request.getServerPort()+path+&/&;
&%@taglib prefix=&c& uri=&/jsp/jstl/core& %&
&!DOCTYPE HTML PUBLIC &-//W3C//DTD HTML 4.01 Transitional//EN&&
&base href=&&%=basePath%&&&
&title&My JSP 'loginUI.jsp' starting page&/title&
&meta http-equiv=&pragma& content=&no-cache&&
&meta http-equiv=&cache-control& content=&no-cache&&
&meta http-equiv=&expires& content=&0&&
&meta http-equiv=&keywords& content=&keyword1,keyword2,keyword3&&
&meta http-equiv=&description& content=&This is my page&&
&link rel=&stylesheet& type=&text/css& href=&styles.css&&
&!-- 如果session中有user对象 --&
&c:if test=&${not empty user }&&&jsp:forward page=&/WEB-INF/pages/login.jsp&/&&/c:if&
&form action=&${pageContext.request.contextPath }/Login& method=&post&&
用户名:&input type=&text& name=&userName& value=&${param.userName }&&&span class=&error&&${errors.userName}&/span&&br/&
密码:&input type=&password& name=&password& value=&${param.password }&&&span class=&error&&${errors.password}&/span&&br/&
&input type=&submit& name=&submit& value=&登录&&&br/&
&%@ page language=&java& import=&java.util.*& pageEncoding=&UTF-8&%&
&%@ taglib prefix=&c& uri=&/jsp/jstl/core& %&
String path = request.getContextPath();
String basePath = request.getScheme()+&://&+request.getServerName()+&:&+request.getServerPort()+path+&/&;
&!DOCTYPE HTML PUBLIC &-//W3C//DTD HTML 4.01 Transitional//EN&&
&base href=&&%=basePath%&&&
&title&My JSP 'login.jsp' starting page&/title&
&meta http-equiv=&pragma& content=&no-cache&&
&meta http-equiv=&cache-control& content=&no-cache&&
&meta http-equiv=&expires& content=&0&&
&meta http-equiv=&keywords& content=&keyword1,keyword2,keyword3&&
&meta http-equiv=&description& content=&This is my page&&
&link rel=&stylesheet& type=&text/css& href=&styles.css&&
${user.name }${user.activated?&已激活&:&未激活& } &br&
&c:if test=&${not user.activated }&&
请进入你的邮箱激活账户,如果的你的激活邮件已丢失,请&a href=&${pageContext.request.contextPath }/RenewActivate&&重新获取激活邮件&/a&
如果你原先填写的email地址无法接收到激活邮件,请修改邮箱地址,再去激活。&a href=&${pageContext.request.contextPath }/UpdateAccountUI&&修改邮箱&/a&
updateAccount.jsp
&%@ page language=&java& import=&java.util.*& pageEncoding=&UTF-8&%&
String path = request.getContextPath();
String basePath = request.getScheme()+&://&+request.getServerName()+&:&+request.getServerPort()+path+&/&;
&!DOCTYPE HTML PUBLIC &-//W3C//DTD HTML 4.01 Transitional//EN&&
&base href=&&%=basePath%&&&
&title&My JSP 'updateAccountUI.jsp' starting page&/title&
&meta http-equiv=&pragma& content=&no-cache&&
&meta http-equiv=&cache-control& content=&no-cache&&
&meta http-equiv=&expires& content=&0&&
&meta http-equiv=&keywords& content=&keyword1,keyword2,keyword3&&
&meta http-equiv=&description& content=&This is my page&&
&link rel=&stylesheet& type=&text/css& href=&styles.css&&
&form action=&${pageContext.request.contextPath }/UpdateAccount& method=&post&&
用户名:&input type=&text& name=&userName& value=&${user.name }& readonly&&br/&
邮箱地址:&input type=&text& name=&email& value=&${user.email }&&&span class=&error&&${errors.email}&/span&&br/&
&input type=&submit& name=&submit& value=&修改&&&br/&
web.xml 中
&servlet-mapping&
& & &servlet-name&RegisterUserUI&/servlet-name&
& & &url-pattern&/RegisterUserUI&/url-pattern&
我这里用首字母大写了/RegisterUserUI,还是首小写看着爽,这里就不改了。测试过了,没有问题!
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:515267次
积分:6437
积分:6437
排名:第2727名
原创:183篇
转载:80篇
评论:120条
(1)(4)(14)(2)(36)(84)(37)(47)(22)(6)(5)(1)(4)c#注册发送Email提示激活功能,以及找回密码发送邮件功能 - 开源中国社区
当前访客身份:游客 [
当前位置:
发布于 日 13时,
/*==============================================================================**&Filename:&Emailsend.zip*&Description:&邮件发送功能,主要实现了用户注册邮箱验证,成功后发邮件到注册邮箱中去,然后可以去*&点击连接进行激活,不激活不能进行登录,会提示未激活账号,如果忘记密码可以通过邮箱或者用户名去找回密码*&发邮件到注册的邮箱,可以重新设置密码。然后可以用新密码进行登录。*&如果你想设置发送邮箱可以点击db/ConfigKeyen.exe&工具进行输入需要发送邮件的密码,进行加密,*&把加密后的字符复制到CreateProject/Config/Smtp.config&&中的&&Password&这里放加密后字符串&/Password&*&Version:&1.0*&Created:&*&Author&:&liangjw*&E-mail&:&*&Q&&&Q&&:&*&Profile&Url:http://90ideas.net/*&Company:&Copyright&(C)&Create&Family&Wealth&Power&By&Peter*==============================================================================*/&*&备注信息:&上传部分自己总结的常用方法的封装,有不足和不完美之处,希望大家指出来,愿意一起&*&主要研究erp,cms,crm,b2b,oa等系统和网站的开发,欢迎有共同追求和学的IT人员一起学习和交流。&*&学习和讨论有关asp.net&&mvc&,Ajax&,jquery&,html/css,&xml,sqlserver&,wpf,IIS以及服务器的搭建和安全性相关技术的交流和学习。
代码片段(0)
开源中国-程序员在线工具:
相关的代码(122)
测试了下注册激活邮箱功能,当点击激活成功后,再次点击还是提示激活成功,能否提示该邮箱已经激活呢?用户体验好些
2楼:web天空 发表于
忘记说了,这个代码值得赞!web开发常用技术
3楼:web天空 发表于
调试访问的时候出现如下错误,
Server Error in '/vip' Application.
错误代码行是18行,怎么回事呢:
&sessionState mode=&StateServer& stateConnectionString=&tcpip=127.0.0.1:42424& timeout=&3600&/&
4楼:web天空 发表于
http://bbs.csdn.net/topics/
10楼的回答帮我解决了问题
5楼:lovehelen80 发表于
引用来自“web天空”的评论调试访问的时候出现如下错误,
Server Error in '/vip' Application.
错误代码行是18行,怎么回事呢:
&sessionState mode=&StateServer& stateConnectionString=&tcpip=127.0.0.1:42424& timeout=&3600&/& 我也遇到了和你一样的情况?怎么解决?可否告知?
6楼:web天空 发表于
引用来自“lovehelen80”的评论引用来自“web天空”的评论调试访问的时候出现如下错误,
Server Error in '/vip' Application.
错误代码行是18行,怎么回事呢:
&sessionState mode=&StateServer& stateConnectionString=&tcpip=127.0.0.1:42424& timeout=&3600&/& 我也遇到了和你一样的情况?怎么解决?可否告知?http://bbs.csdn.net/topics/楼的回答
7楼:Clare_zou 发表于
在运行里输入:services&按回车键,打开服务,将服务列表中ASP.NET状态服务开启,最好设置成自动开启& 知其然不知其所以然
8楼:恶魔哥哥 发表于
哪里有10楼?
9楼:web天空 发表于
引用来自“The_Miz”的评论哪里有10楼?http://bbs.csdn.net/topics/楼的回答 有看到前面的网址吗?进去找到第十楼的回答,我是这么解决的,不知道你能不能
10楼:cd3535 发表于
额...没有.cs文件,还是我没有找到
11楼:xuemingjia 发表于
12楼:冯志敏 发表于
怎么下载?
开源从代码分享开始
liangjw0504的其它代码

我要回帖

更多关于 扣扣怎么解绑手机号 的文章

 

随机推荐