jsp代码注册邮箱(jsp实现注册)
admin 发布:2022-12-19 16:17 123
今天给各位分享jsp代码注册邮箱的知识,其中也会对jsp实现注册进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!
本文目录一览:
- 1、JSP如何向注册用户邮箱自动发送帐号和密码
- 2、如何在jsp页面上实现点击注册按钮,弹出一个窗体来注册(类似于百度贴吧的登录和注册),求详细代码和注释
- 3、求大神写一下jsp的简单的注册界面代码。
- 4、jsp 登陆和注册问题
- 5、JSP 想实现会员注册时,系统自动发送邮件到用户邮箱实现点击激活,网上有例子,但只是原理,如何实现?
- 6、在jsp页面中添加邮箱验证,我这怎添加呢?
JSP如何向注册用户邮箱自动发送帐号和密码
当用户注册提交信息后,如果用户数据录入成功,使用javamail组件通过支持外部smtp发送邮件的账户邮箱向注册用户的EMAIL发送邮件.
javamail下载地址:
另外apache基金会的Apache Common Mail更好的封装了javamail使用接口
发送邮件非常的简单
下载地址:
目前能支持SMTP外部发送邮件的有QQ邮箱 GMAIL邮箱
也可以购买mail服务
具体使用举例见:
如何在jsp页面上实现点击注册按钮,弹出一个窗体来注册(类似于百度贴吧的登录和注册),求详细代码和注释
jsp中的注册弹出新窗口是通过window.open一个新页面来实现的。
页面register.jsp代码如下:
%@ page contentType="text/html; charset=gb2312" language="java" import="cn.wy.Pet.User" errorPage="" %
!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ""
html xmlns=""
head
meta http-equiv="Content-Type" content="text/html; charset=gb2312" /
title会员注册例子讲解/title
style type="text/css"
!--
.STYLE1 {
color: #FF0000;
font-weight: bold;
}
.STYLE2 {color: #FF0000}
.STYLE3 {
font-size: 18px;
font-weight: bold;
}
--
/style
/head
body style="font-size:12px"
form id="form1" name="form1" method="post" action="%=actionStr%reg"
p align="center"br /
span class="STYLE3"用户注册/span/p
table width="582" height="302" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#BCACD2"
tr
td width="80" align="right"用户名:/td
td width="496" align="left"input name="userName" type="text" id="userName" size="16" maxlength="16" /
span class="STYLE1"*/span 3~16位字母或者数字(如:8hack)/td
/tr
tr
td align="right"密码:/td
td align="left"input name="password1" type="text" id="password1" size="16" maxlength="16" /
span class="STYLE1"* /span 3~16位字母或者数字(如:abc123)/td
/tr
tr
td align="right"确认密码:/td
td align="left"input name="password2" type="text" id="password2" size="16" maxlength="16" /
span class="STYLE1"*/span 必须和上面输入的密码相同/td
/tr
tr
td align="right"电子邮件:/td
td align="left"input name="email" type="text" id="email" maxlength="20" /
span class="STYLE1"*/span 找回密码和联系用(如:8hack@163.com)/td
/tr
tr
td align="right"联系电话:/td
td align="left"input name="tel" type="text" id="tel" size="20" maxlength="20" /
如(0871-8888888,13888853113)/td
/tr
tr
td align="right"联系地址:/td
td align="left"input name="address" type="text" id="address" maxlength="50" //td
/tr
td height="40" colspan="2" align="center"input type="submit" name="Submit" value="确认注册" /
input type="reset" name="Submit2" value="重新填写" //td
/tr
/table
/form
/body
/html
后台servlet的处理:
public class reg extends HttpServlet
{
public reg()
{
}
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
PrintWriter out;
DBConnection dbc=null;
String userName;
String psd;
String email;
String tel;
String address;
int popedom;
response.setContentType("text/html;charset=UTF-8");
out = response.getWriter();
try{
dbc = new DBConnection();
PreparedStatement ps = null;
userName = request.getParameter("userName");
psd = login.encrypt(request.getParameter("password1").toString());
email = request.getParameter("email");
tel = request.getParameter("tel");
address = request.getParameter("address");
popedom = Integer.parseInt(request.getParameter("popedom"));
if (userName != null psd != null email != null)
{
ps = dbc.getCon().prepareStatement("insert into [User](UName,Upass,UEmail,UTel,UAddress,UPopedom) values(?,?,?,?,?,?)");
ps.setString(1, userName);
ps.setString(2, psd);
ps.setString(3, email);
ps.setString(4, tel);
ps.setString(5, address);
ps.setInt(6, popedom);
ps.execute();
System.out.print("新用户注册:" + request.getParameter("userName") + " ");
out.print("scriptalert('恭喜您:注册成功!现已经登录到网站!');history.go(-1)/script");
}
if (dbc != null)
dbc.dbClose();
}
catch(SQLException ex)
{
out.print("scriptalert('注册失败!数据库连接错误!');history.go(-1)/script");
ex.printStackTrace();
if (dbc != null)
dbc.dbClose();
}
}
}
求大神写一下jsp的简单的注册界面代码。
1.需要一个jsp页面:
//login.jsp核心代码:
form action="${pageContext.request.contextPath}/servlet/UserServlet" method="post"
input type="text" name="loginname" /input type="password" name="password"/
input type="submit" value="登录"/
/form
2.需要一个servlet来验证登录信息
//UserServlet 核心代码
class UserServlet extends HttpServlet{
protected void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
process(request, response);
}
protected void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
process(request, response);
}
private void process(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
PrintWriter pw = response.getWriter();
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html");
String loginname = request.getParameter("loginname");
String password = request.getParameter("password");
//创建一个service来处理业务逻辑(包括查询数据库操作)
UserService service = new UserService();
boolean bool = service.validateUser(loginname,password);
if(!bool){
pw.println("用户名或密码错误");
}else{
pw.println("登录成功");
}
}
3.需要一个service处理业务逻辑(包括查询数据库操作)
//UserService 核心代码
public class UserService{
/**
*查询数据库验证用户是否存在,返回boolean
*/
public boolean validateUser(String loginname,String password){
boolean bool = false;
Connection conn = null;
PreparedStatement ps = null;
//这里以mysql为例
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "");
String sql = "select login_name,pass_word from t_user where login_name=? and pass_word=?";
ps = conn.prepareStatement(sql);
ps.setString(0, loginname);
ps.setString(1, password);
ResultSet rs = ps.executeQuery();
if(rs.next()){
bool = true;
}
} catch (Exception e) {
e.printStackTrace();
} finally{
try {
if(conn != null){
conn.close();
conn = null;
}
if(ps != null){
ps.close();
ps = null;
}
} catch (SQLException e) {
e.printStackTrace();
}
}
return bool;
}
}
jsp 登陆和注册问题
一般地,没必要就不要用JSP代码:
html
head
title用户登陆/title
script language="JavaScript" type="text/JavaScript"
//return false不会提交,true则提交
function check() {
var userName = document.all("userName").value;
var password = document.all("password").value;
if (userName == "") {
alert('用户名不能为空');
return false;
} else if (password == "") {
alert('密码不能为空');
return false;
}
return true;
}
/script
/head
body onload="focus()"
Form id="login" name="login" action="请求路径"
onsubmit="return check()"
input name='userName' id='userName'
input name='password' id='password'
input type="submit" value='submit'
/Form
/body
/html
JSP 想实现会员注册时,系统自动发送邮件到用户邮箱实现点击激活,网上有例子,但只是原理,如何实现?
一.程序源码:
(1) 发送文本类型信件.这种是接收者收到后打开信箱后直接显示在邮件正文的.它主要有两个程序: mailform.html and sendmail.jsp,另外三个程序为提交成功和不成功及发生内部错误的处理程序.
mailform.html用来输入用户信息,然后提交表单给sendmail.jsp
sendmail.jsp 用来处理接收信息并处理信息,最后发送邮件.
%--mailform.html 的源代码--%
!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
html
head
titlemailform.html/title
meta http-equiv="Content-Type" content="text/html; charset=gb2312"
/head
body
form name="form1" method="post" action="sendmail.jsp"
p align="center"填写邮件内容/p
div align="center"
table width="75%" border="1"
tr
tddiv align="center"收件人/div/td
tddiv align="center"
input name="to" type="text" id="to" size="30" maxlength="30"
/div/td
/tr
tr
tddiv align="center"发件人/div/td
tddiv align="center"
input name="from" type="text" id="from" size="30" maxlength="30"
/div/td
/tr
tr
tddiv align="center"抄送/div/td
tddiv align="center"
input name="cc" type="text" id="cc" size="30" maxlength="100"
/div/td
/tr
tr
tddiv align="center"暗送/div/td
tddiv align="center"
input name="bcc" type="text" id="bcc" size="30" maxlength="100"
/div/td
/tr
tr
tddiv align="center"主题/div/td
tddiv align="center"
input name="subject" type="text" id="subject" size="30" maxlength="30"
/div/td
/tr
tr
td colspan="2"div align="center"
textarea name="body" cols="40" rows="10" id="body"/textarea
/div/td
/tr
tr
td colspan="2"div align="center"
input type="submit" name="Submit" value="发送"
input name="Reset" type="submit" id="Reset" value="清空"
/div/td
/tr
/table
/div
p align="center" /p
/form
p align="center" /p
/body
/html
%--sendmail.jsp 的源代码--%
%@page contentType="text/html;charset=gb2312"%
%@page errorPage="errpage.jsp"%
%@page import="java.util.*"%
%@page import="javax.mail.*"%
%@page import="javax.mail.internet.*"%
%@page import="javax.activation.*"%
html
head
titlesendmail.jsp/title
meta http-equiv="Content-Type" content="text/html; charset=gb2312"
/head
body
%
//邮件服务器的IP地址,注意此时使用的是SMTP 邮件服务器
//String host="202.102.240.76";
//获取用户信息
String to=request.getParameter("to");
String from=request.getParameter("from");
String cc=request.getParameter("cc");
String bcc=request.getParameter("bcc");
//结合本程序的第一句,共同起显示汉字体的功能
String subject=request.getParameter("subject");
subject = new java.lang.String(subject.getBytes("iso-8859-1"));
//以上方法等同于以下两句,原理相同
//byte[] subjectTemp=request.getParameter("subject").getBytes("ISO8859_1");
//String subject=new String(subjectTemp);
byte[] messageTextTemp=request.getParameter("body").getBytes("ISO8859_1");
String messageText= new String(messageTextTemp);
boolean sessionDebug = false;
//验证所填写的邮件是否正确
if((to.trim().indexOf("@")==-1)||(to.trim().length()5)){
%
jsp:forward page="err.jsp"/
%
}
if((from.trim().indexOf("@")==-1)||(from.trim().length()5)){
%
jsp:forward page="err.jsp"/
%
}
//获得系统属性对象,用下两句的任一句均可
//Properties props = System.getProperties();
Properties props=new Properties();
//设置SMTP主机
//以下一句是对任意的SMTP 邮件服务器均可,并且有了这一句,将不用设置传输协议了
props.put("mail.smtp.host", "smtp.jspinsider.com");
//这样将确定接收方的邮件服务器主机,
//props.put("mail.host",host);
//设置邮件传输协议方式
//props.put("mail.transport.protocol","smtp");
//获取邮件会话对象
Session mailSession = Session.getDefaultInstance(props,null);
mailSession.setDebug(sessionDebug);
try{
//创建MIME邮件对象
Message msg = new MimeMessage(mailSession);
//设置发信人
msg.setFrom(new InternetAddress(from));
//设置收信人
InternetAddress[] addressTo = {new InternetAddress(to)};
msg.setRecipients(Message.RecipientType.TO,addressTo);
//设置抄送人
if(cc.trim().length()!=0){
InternetAddress[] addressCc = {new InternetAddress(cc)};
msg.setRecipients(Message.RecipientType.CC,addressCc);
}
//设置暗送人
if(bcc.trim().length()!=0){
InternetAddress[] addressBcc = {new InternetAddress(bcc)};
msg.setRecipients(Message.RecipientType.BCC,addressBcc);
}
msg.setSubject(subject);
msg.setSentDate(new Date());
msg.setText(messageText);
//发送邮件
Transport.send(msg);
}
catch(Except
jsp如何实现发送电子邮件2007年11月07日 星期三 下午 11:35
关键字:|发送到邮件功能实现|网站建设|功能组件|在线发邮件|文章发送到邮件|
一、准备工作很麻烦 整理:
1、下载javamail的包
java.sun.com/products/javamail/downloads/index.html
将 mail.jar 复制到 lib 目录中
2、下载activation 包
java.sun.com/products/javabeans/jaf/downloads/index.html
将activation.jar复制到 lib 目录中
3、再把服务器重启下
二、下面是一个简单的发送文本内容的例子,直接在jsp中进行操作。可以自己设置smtp的地址,用户名和密码,这是javamail最简单的应用,它的功能超强,可以发附件,可以收邮件等。
%@page contentType="text/html;charset=gb2312"%
%@ page import="javax.mail.*,javax.activation.*,javax.mail.internet.*,java.util.*"%
html
head
titleJavaMail 电子邮件发送/title
/head
body
%!
public class MailAuthenticator extends Authenticator{
String authenName;
String authenPass;
public MailAuthenticator(String authenName,String authenPass) {
super();
this.authenName=authenName;
this.authenPass=authenPass;
}
public PasswordAuthentication getPasswordAuthentication(){
return new PasswordAuthentication(authenName,authenPass);
}
}
%
%
MailAuthenticator ma = new MailAuthenticator("","");
//这里第一个参数是用户名,第二个是密码。 如果是匿名服务器,可以设置为空
Properties props = new Properties();
Session sendMailSession;
Transport transport;
sendMailSession = Session.getInstance(props,ma);
Message newMessage = new MimeMessage(sendMailSession);
newMessage.setFrom(new InternetAddress("test@test.com")); //发件人
newMessage.setRecipient(Message.RecipientType.TO, new InternetAddress("wxg_bj@yahoo.com.cn")); //目标邮箱
newMessage.setSubject("subject"); //这个是标题
newMessage.setSentDate(new Date());
newMessage.setText("text"); //文本内容
props.put("mail.smtp.host","192.168.0.1");//这里设置smtp服务器地址 ,我设置的是本机
props.put("mail.smtp.auth","true");//这里true代表需要密码验证,如果是匿名服务器,可以设置为false,当然,设置为ture也无所谓,只要名和密码设置为空
transport = sendMailSession.getTransport("smtp");
try{
transport.send(newMessage);
//发送
}catch(Exception e){
System.out.println(e);
}
%
/BODY
/HTML
项目导入mail.jar了吗?
protected PasswordAuthentication getPasswordAuthentication()
{
//这里的USER_NAME和USER_PWD分别写你的邮箱名和密码,不写密码怎么发送呢?
return new PasswordAuthentication(USER_NAME,USER_PWD);
//我看你是做了张jsp网页,然后通过request.getParameter获取页面值,那这也要接受的
}
这句话好象没写.
prop.put("mail.smtp.host",HOST_NAME);
最后补充一点.有时候代码完全正确,也会不能发送.因为你的邮箱没得到验证,近几年申请的普通邮箱都是没通过验证的.所以你是那种邮箱的话就没办法了.
在jsp页面中添加邮箱验证,我这怎添加呢?
"您好,
用QQ邮箱吧,只要有QQ,通过手机或电脑浏览器mail.qq.com登陆即可激活开通邮箱,邮箱填写:QQ号@qq.com,没有就到zc.qq.com注册一下,支持注册任何需要邮箱的平台。
用户名支持设置为【英文@qq.com】【手机@qq.com】【用户名@foxmail.com】商务两用,这个功能是实现一个邮箱拥有多个邮箱地址,意思是所有设置的邮箱地址都会收到同一个邮箱。
设置方法:
1、通过电脑浏览器登陆网页版,
2、左上角设置---选择账户---即可注册其它用户名,
同时邮箱要是用的多,建议装个专业手机QQ邮箱客户端4.0,通过浏览器或app搜索即可下载,安装好打开软件---添加邮箱选择对应服务商---输入帐 号和密码即可绑
定,支持imap/pop3/exchange绑定和多帐号管理,设置简单,新邮件即时提醒,同步通讯录,集成漂流瓶让邮箱更加有趣,文件中转 站,日历添加行程安排提醒,记事
本,广告邮件汇聚,还有夜间免打扰设置等功能。
希望对你有所帮助!"
jsp代码注册邮箱的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于jsp实现注册、jsp代码注册邮箱的信息别忘了在本站进行查找喔。
版权说明:如非注明,本站文章均为 AH站长 原创,转载请注明出处和附带本文链接;
- 上一篇:射击类小游戏代码(射击编程代码)
- 下一篇:kingcms文章标题调用代码的简单介绍
相关推荐
- 05-09网页代码,网页代码快捷键
- 05-07万网域名注册查询网,万网域名查询和注册
- 05-06单页网站的代码(完整的网页代码)[20240506更新]
- 05-06个人主页图片代码(个人主页图片代码怎么弄)[20240506更新]
- 05-06提取微信名片代码(微信名片信息提取)[20240506更新]
- 05-06php后台权限管理代码(php管理员权限)[20240506更新]
- 05-06付费观看代码php(付费观看代码)[20240506更新]
- 05-06在线html执行代码(html怎么运行)[20240506更新]
- 05-06源代码管理资源管理器(资源管理器运行代码)[20240506更新]
- 05-06代码源软件库(程序代码库)[20240506更新]
取消回复欢迎 你 发表评论:
- 标签列表
- 最近发表
- 友情链接