• 大小: 1.19MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-11-05
  • 语言: Java
  • 标签:

资源简介

此Demo通过java实现了用户注册时,向用户邮箱发送激活链接,并且用户点击激活链接之后激活用户的状态。

资源截图

代码片段和文件信息

package dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class UserDao {
public Boolean AddUser(String usernameString passwordString emailString code){
Boolean result=false;
Connection conn=null;
String sql=“insert into t_user(usernamepasswordemailcodestate) values(?????)“;
try {
//注册驱动
Class.forName(“com.mysql.jdbc.Driver“);
//建立连接
conn=DriverManager.getConnection(“jdbc:mysql://localhost:3306/SendMail““root““dannyhoo“);
PreparedStatement pstmt=conn.prepareStatement(sql);
pstmt.setString(1username);
pstmt.setString(2password);
pstmt.setString(3email);
pstmt.setString(4code);
pstmt.setInt(50);
result=pstmt.execute();
}catch(ClassNotFoundException e){
e.printStackTrace();
}catch (SQLException e) {
e.printStackTrace();
}
return result;
}

public String findUserByCode(String code) {
String username=““;
Connection conn=null;
ResultSet rs=null;
String sql=“select username from t_user where code=?“;
try {
//注册驱动
Class.forName(“com.mysql.jdbc.Driver“);
//建立连接
conn=DriverManager.getConnection(“jdbc:mysql://localhost:3306/SendMail““root““dannyhoo“);
PreparedStatement pstmt=conn.prepareStatement(sql);
pstmt.setString(1code);
rs=pstmt.executeQuery();
if(rs.next()){
username=rs.getString(“username“);
}
}catch(ClassNotFoundException e){
e.printStackTrace();
}catch (SQLException e) {
e.printStackTrace();
}
return username;
}

/**
 * 将用户状态设为可用
 * @param username
 */
public Boolean setState(String username) {
Boolean result=false;
Connection conn=null;
String sql=“update t_user set state=1 where username=?“;
try {
//注册驱动
Class.forName(“com.mysql.jdbc.Driver“);
//建立连接
conn=DriverManager.getConnection(“jdbc:mysql://localhost:3306/SendMail““root““dannyhoo“);
PreparedStatement pstmt=conn.prepareStatement(sql);
pstmt.setString(1username);
int i=pstmt.executeUpdate();
if(i>0){
result=true;
}
}catch(ClassNotFoundException e){
e.printStackTrace();
}catch (SQLException e) {
e.printStackTrace();
}
return result;
}
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2015-08-27 15:10  SendMail\
     文件         841  2015-08-27 15:10  SendMail\.classpath
     文件        1041  2015-08-27 15:10  SendMail\.project
     目录           0  2015-08-27 15:10  SendMail\.settings\
     文件         503  2015-08-27 15:10  SendMail\.settings\.jsdtscope
     文件         364  2015-08-27 15:10  SendMail\.settings\org.eclipse.jdt.core.prefs
     文件         476  2015-08-27 15:10  SendMail\.settings\org.eclipse.wst.common.component
     文件         345  2015-08-27 15:10  SendMail\.settings\org.eclipse.wst.common.project.facet.core.xml
     文件          49  2015-08-27 15:10  SendMail\.settings\org.eclipse.wst.jsdt.ui.superType.container
     文件           6  2015-08-27 15:10  SendMail\.settings\org.eclipse.wst.jsdt.ui.superType.name
     目录           0  2015-08-27 15:10  SendMail\build\
     目录           0  2015-08-27 17:04  SendMail\build\classes\
     目录           0  2015-08-27 17:04  SendMail\build\classes\dao\
     文件        2903  2015-08-27 17:04  SendMail\build\classes\dao\UserDao.class
     目录           0  2015-08-27 17:46  SendMail\build\classes\service\
     文件        3990  2015-08-27 17:49  SendMail\build\classes\service\UserManager.class
     目录           0  2015-08-27 17:04  SendMail\build\classes\servlet\
     文件        1571  2015-08-27 17:04  SendMail\build\classes\servlet\ActiveServlet.class
     文件        1642  2015-08-27 17:04  SendMail\build\classes\servlet\RegisterServlet.class
     目录           0  2015-08-27 15:35  SendMail\src\
     目录           0  2015-08-27 15:36  SendMail\src\dao\
     文件        2393  2015-08-27 16:21  SendMail\src\dao\UserDao.java
     目录           0  2015-08-27 15:24  SendMail\src\service\
     文件        3186  2015-08-27 17:49  SendMail\src\service\UserManager.java
     目录           0  2015-08-27 16:05  SendMail\src\servlet\
     文件         887  2015-08-27 16:42  SendMail\src\servlet\ActiveServlet.java
     文件         867  2015-08-27 16:42  SendMail\src\servlet\RegisterServlet.java
     目录           0  2015-08-27 16:39  SendMail\WebContent\
     目录           0  2015-08-27 15:10  SendMail\WebContent\meta-INF\
     文件          39  2015-08-27 15:10  SendMail\WebContent\meta-INF\MANIFEST.MF
     文件         634  2015-08-27 15:22  SendMail\WebContent\register.jsp
............此处省略6个文件信息

评论

共有 条评论