Java-Web(项目)优化登录注册
Java-Web(项目)优化登录注册
实现代码:
package com.homework.dao1;
public interface Login {
public String doLogin(String _username,String _password);
}
```java
package com.homework.dao1;
import com.homework1.pojo.Employee;
public interface Register {
public String doRegister(Employee _employee);
}
package com.homework1.pojo;
public class Employee {
private String RegisterName;
private String repassword;
private String rerepassword;
private int sex;
private String prical;
private String email;
public String getRegisterName() {
return RegisterName;
}
public void setRegisterName(String registerName) {
RegisterName = registerName;
}
public String getRepassword() {
return repassword;
}
public void setRepassword(String repassword) {
this.repassword = repassword;
}
public String getRerepassword() {
return rerepassword;
}
public void setRerepassword(String rerepassword) {
this.rerepassword = rerepassword;
}
public int getSex() {
return sex;
}
public void setSex(int sex) {
this.sex = sex;
}
public String getPrical() {
return prical;
}
public void setPrical(String prical) {
this.prical = prical;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
}
```java
package com.homework.dao.impl;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import com.homework.dao1.Login;
import com.homework2.Until.DBConn;
public class LoginImpl implements Login {
//验证登录是否成功
public String doLogin(String _username,String _password){
Connection conn = null;
PreparedStatement pst = null;
ResultSet rs = null;
String result = "";
String sql = "select * from loginuser where userName=? and userPwd=? ";
try {
DBConn db = new DBConn();
conn = db.getConnection();
pst = conn.prepareStatement(sql);
pst.setString(1,_username);
pst.setString(2,_password);
rs = pst.executeQuery();
} catch (SQLException e1) {
e1.printStackTrace();
}
try {
if(rs.next()){
result = "success";
}else{
result = "fail";
}
DBConn.closeAll(rs, pst, null);
} catch (SQLException e) {
e.printStackTrace();
}
return result;
}
}
package com.homework.dao.impl;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import com.homework.dao1.Register;
import com.homework1.pojo.Employee;
import com.homework2.Until.DBConnUtils;
public class RegisterImpl implements Register {
public String doRegister (Employee _employee){
Connection conn = null;
PreparedStatement pst = null;
String result="";
int count = 0;
String sql = "insert into loginuser(userName,userPwd,userRePwd,sex,princal,email) values(?,?,?,?,?,?)";
conn = DBConnUtils.getConnection();
try {
pst = conn.prepareStatement(sql);
pst.setString(1,_employee.getRegisterName());
pst.setString(2,_employee.getRepassword());
pst.setString(3,_employee.getRerepassword());
pst.setInt(4,_employee.getSex());
pst.setString(5,_employee.getPrical());
pst.setString(6,_employee.getEmail());
count = pst.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
}
if(count > 0){
result = "success";
}else{
result = "fail";
}
DBConnUtils.closeALL(null, pst, conn);
return result;
}
}
package com.homework2.Until;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
public class ConfigManager {
private static Properties properties = null;
static{
InputStream is = null;
is = ConfigManager.class.getClassLoader().getResourceAsStream("database.properties");
if(is==null){
throw new RuntimeException("找不到配置文件");
}
properties = new Properties();
try {
properties.load(is);
} catch (IOException e) {
e.printStackTrace();
}finally{
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
public static String getProperty(String key){
return properties.getProperty(key);
}
}
package com.homework2.Until;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;
public class DBConn {
public Connection conn;
Context ctx = null;
//定义创建连接的方法
public Connection getConnection(){
try {
ctx = new InitialContext();
DataSource ds = (DataSource) ctx.lookup("java:comp/env/jdbc/hospital1");
conn = ds.getConnection();
} catch (Exception e) {
e.printStackTrace();
}
return conn;
}
public static void closeAll(ResultSet rs,Statement st, Connection conn){
//关闭结果集
if(rs != null){
try {
rs.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if(st != null){
try {
st.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if(conn != null){
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
package com.homework2.Until;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class DBConnUtils {
static String driver = ConfigManager.getProperty("driver");
static String url = ConfigManager.getProperty("url");
static String username = ConfigManager.getProperty("username");
static String password = ConfigManager.getProperty("password");
public static Connection getConnection(){
Connection conn = null;
try {
Class.forName(driver);
//创建数据库连接
conn=DriverManager.getConnection(url, username, password);
} catch (Exception e) {
e.printStackTrace();
}
return conn;
}
public static void closeALL(ResultSet rs,Statement st,Connection conn){
//关闭结果集
if(rs != null){
try {
rs.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if(st != null){
try {
st.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if(conn != null){
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
public static ResultSet getQueryList(Connection _conn,Statement _st,String _sql){
ResultSet rs = null;
try {
rs = _st.executeQuery(_sql);
} catch (SQLException e) {
e.printStackTrace();
}
return rs;
}
}
package com.homework3.com;
import com.homework1.pojo.Employee;
public interface LoginService {
public String Login(Employee _employee);
}
package com.homework3.com;
import com.homework1.pojo.Employee;
public interface RegisterService {
public String Register(Employee _employee);
}
package com.homework3.com.impl;
import com.homework.dao.*;
import com.homework.dao.impl.LoginImpl;
import com.homework1.pojo.Employee;
import com.homework3.com.LoginService;
public class LoginServiceImpl implements LoginService {
com.homework.dao1.Login login = null;
public String Login(Employee _employee){
login=new LoginImpl();
return login.doLogin(_employee.getRegisterName(), _employee.getRepassword());
}
}
package com.homework3.com.impl;
import com.homework.dao.impl.RegisterImpl;
import com.homework1.pojo.Employee;
import com.homework3.com.RegisterService;
public class RegisterServiceImpl implements RegisterService {
com.homework.dao1.Register register = null;
public String Register(Employee _employee){
register = new RegisterImpl();
return register.doRegister(_employee);
}
}
实现效果:
依然可以登入以及注册:
以上均为个人所写,还有些许不熟,会加以改进,如有错误,欢迎指出,谢谢!
Java-Web(项目)优化登录注册相关教程
k8s集成Jenkins实现项目自动上线
k8s集成Jenkins实现项目自动上线 k8s对接Jenkins 1.开发还是一样的写java代码,写好java代码后提交到gitlab仓库中,Jenkins在通过gitlab去拉取这些代码,开发只需要在Jenkins页面上点一下立即构建,就会调用shell命令将代码通过docker build 来构建镜像。2.do
SpringBoot 教程 | 第一篇: SpringBoot项目整合Swagger2(Spring
SpringBoot 教程 | 第一篇: SpringBoot项目整合Swagger2(SpringBoot+Swagger2)(2.6.1版本) 一、项目添加Swagger pom依赖 dependency groupIdio.springfox/groupId artifactIdspringfox-swagger2/artifactId version2.6.1/version/dependencydependency grou
VUE 之web端项目创建
VUE 之web端项目创建 前言 因为项目业务需要,接触了一段时间的Vue开发,作为一名新手记录下学习过程 一、 Vue Web端创建项目 1. Node 安装 下载Node解压后双击 node-v6.14.4-x64.msi(版本号可能不同)安装,在安装界面一直Next,直到Finish完成安装。 打开
vue项目中引用cdn资源与项目配置(详解)
vue项目中引用cdn资源与项目配置(详解) 一、CDN是什么 CDN(内容分发网络)本身是指一种请求资源的方式。说白了就是在本地,通过script头去请求对应的脚本资源的一种方式。我在这里要说的就是直接引用 或者下载Vue.js放在本地,进行项目开发的方式。而不是通
内存优化系列文章(3)程序员眼中的虚拟内存管理
内存优化系列文章(3)程序员眼中的虚拟内存管理 虚拟内存的初衷是采用页表管理机制使得程序即使在物理内存不足时也可以运行。在内存大幅度增加的当下,你可能会问虚拟内存还有用吗?如果你只是普通用户,买根内存条完事!但作为一名软件工程师,虚拟内存管理
中小型企业网站项目
中小型企业网站项目 centos-60 centos-70 各添加一块硬盘,并格式化为xfs格式 blkid fdisk /dev/sdb mkfs.xfs /dev/sdb1 创建保存数据库的目录授权并挂载到硬盘 mkdir /data mount /dev/sdb1 /data/ chown -R mysql:mysql/data/ df -hT 安装 MySQL 5.7 版本:
项目上线之——部署服务器
项目上线之——部署服务器 项目开发完成以后,合并代码成果到master分支。部署到云服务器上运行。 首先,在服务器上创建文件夹放项目 mkdir -p project/{code,conf,logs,static} 将代码部分克隆到 code 文件夹中 cd project/cd codegit clone [emailprotected
20-Vue实战项目:电商管理系统(Element-UI)--vue ui没有反应
20-Vue实战项目:电商管理系统(Element-UI)--vue ui没有反应 在运行vue ui命令时没有反应,原因是vue cli 版本不是3.0及以上。 win+R,输入cmd,打开命令行: vue -V //查看vue cli版本vue -h //查看是否有ui功能 npm uninstall vue-cli -g //卸载旧版本npm