栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

javaweb连接MySql数据库实现注册和登录功能

javaweb连接MySql数据库实现注册和登录功能

1.登录页面(login.jsp)

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>




登录页面


用户名:
密码:

2.登录检查页面(连接数据库部分)(login_check.jsp)

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ page import="java.sql.*" %>




登录检查


<%
String name=request.getParameter("vname");
String pwd=request.getParameter("vpwd");

%>
<%!
public static final String DBDRIVER="org.gjt.mm.mysql.Driver";
public static final String DBURL="jdbc:mysql://localhost:3306/user";//最后一个是数据库名
public static final String DBUSER="root";
public static final String DBPASS="123456";
%>
<%
Connection conn=null;
PreparedStatement pstmt=null;
ResultSet rs=null;
boolean flag=false;
%>
<%
try{
	Class.forName(DBDRIVER);
	conn=DriverManager.getConnection(DBURL, DBUSER, DBPASS);
	String sql="select * from user11 where name=? and password=?";
	pstmt=conn.prepareStatement(sql);
	pstmt.setString(1,name);
	pstmt.setString(2,pwd);
	rs=pstmt.executeQuery();
	if(rs.next())
	{
		flag=true;
	}
}catch(Exception e)
{
	System.out.println("数据库操作异常了!");
	}finally{
		try{
			rs.close();
			pstmt.close();
			conn.close();
		}catch(Exception e)
		{
			System.out.println("数据库关闭异常");
		}
	}

%>
<%
if(flag)
{
%>



<%
}else{
%>

<%
}
%>

3.登录成功页面(success.jsp)

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>




登录成功


欢迎<%=request.getParameter("vname") %>登录

4.登录失败页面(failure.jsp)

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>




登录失败


登录失败了,重新返回登录页面

5.注册页面(register.jsp)

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>




Insert title here


用户名:
密码:

 6.注册检查页面(register_check.jsp)

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
     <%@ page import="java.sql.*" %>




注册检查


<%
String name=request.getParameter("yhm");
String pwd=request.getParameter("mm");

%>
<%System.out.println(name+pwd); %>
<%!
public static final String DBDRIVER="org.gjt.mm.mysql.Driver";
public static final String DBURL="jdbc:mysql://localhost:3306/user";//最后一个是数据库名
public static final String DBUSER="root";
public static final String DBPASS="123456";
%>
<%
Connection conn=null;
PreparedStatement pstmt=null;
ResultSet rs=null;
boolean flag=false;
%>
<%
try{
	
	String sql="insert into user11(name,password) values(?,?)";
	Class.forName(DBDRIVER);
	conn=DriverManager.getConnection(DBURL, DBUSER, DBPASS);
	pstmt=conn.prepareStatement(sql);
	pstmt.setString(1,name);
	pstmt.setString(2,pwd);
	int row=pstmt.executeUpdate();
	if(row>=1)
	{
		flag=true;
	}
}catch(Exception e)
{
	System.out.println("数据库操作异常了!");
	}finally{
		try{
			pstmt.close();
			conn.close();
		}catch(Exception e)
		{
			System.out.println("数据库关闭异常");
		}
	}
%>
<%
if(flag){
%>

<% 
}else{
%>

<%
}
%>

 7.注册成功页面(register_success.jsp)

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>




注册成功


8.注册失败页面(register_failure.jsp)

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>




Insert title here


 

 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/335469.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号