最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

eclipse連接數(shù)據(jù)庫(kù)并實(shí)現(xiàn)用戶(hù)注冊(cè)登錄功能

 更新時(shí)間:2021年01月22日 08:35:51   作者:Stray.io  
這篇文章主要介紹了eclipse連接數(shù)據(jù)庫(kù)并實(shí)現(xiàn)用戶(hù)注冊(cè)登錄功能的相關(guān)資料,需要的朋友可以參考下

文章目錄 MySQL配置環(huán)境變量navicat部署tomcat導(dǎo)入驅(qū)動(dòng)修改代碼連接mysql數(shù)據(jù)庫(kù)運(yùn)行:

MySQL配置環(huán)境變量

mysql肯定是必不可少的,這個(gè)就不用多說(shuō)了,自己去官網(wǎng)下載就行我們來(lái)配置一下mysql的環(huán)境變量

步驟:

我的電腦右鍵——屬性——高級(jí)系統(tǒng)——環(huán)境變量

在這里插入圖片描述

在系統(tǒng)變量下點(diǎn)擊新建:

在這里插入圖片描述

變量名:MYSQL_HOME
變量值:C:\phpStudy\PHPTutorial\MySQL

這里的變量值填的是自己mysql所在的文件夾,以自己電腦路徑為準(zhǔn)

在這里插入圖片描述

然后找到path,點(diǎn)擊編輯,然后新建一個(gè)

%MYSQL_HOME%\bin

在這里插入圖片描述

點(diǎn)擊確定(共三個(gè))
測(cè)試
在windows命令行下輸入

mysql -u root -p

按下回車(chē),輸入密碼即可進(jìn)入數(shù)據(jù)庫(kù)

在這里插入圖片描述

navicat

我自己電腦用的是phpstudy,感覺(jué)更方便一點(diǎn),集成環(huán)境,并且有可視化工具,這里推薦使用navicat(有破解教程)

鏈接: https://pan.baidu.com/s/1dpNhsSUy_yAw-qi63toSzQ

提取碼: wumm

部署tomcat

我們點(diǎn)擊菜單欄windows>>preference>>在左邊欄找到server>>Runtime Environme

在這里插入圖片描述

點(diǎn)擊add,添加tomcat

在這里插入圖片描述

選擇需要的版本,點(diǎn)擊next,選擇自己安裝的tomcat路徑

在這里插入圖片描述

點(diǎn)擊finish:

在這里插入圖片描述

tomcat版本不要太高,不然可能會(huì)出現(xiàn)報(bào)錯(cuò);

新建一個(gè)web項(xiàng)目

在這里插入圖片描述
在這里插入圖片描述

其他選擇默認(rèn),next>>next>>next>>finish

將tomcat服務(wù)器顯示在控制臺(tái)上,以及將web應(yīng)用部署到tomcat中

1、window>>show view>>servers
2、點(diǎn)擊控制臺(tái)鏈接:No servers are available. Click ths link to create a new server.
3、在彈出的對(duì)話(huà)框中選擇tomcat版本
4、點(diǎn)擊next,添加我們的項(xiàng)目:選中我們的項(xiàng)目,點(diǎn)擊add,finish。

我們會(huì)在右邊菜單欄看到文件夾servers,里邊就是tomcat的一些相關(guān)文件

右鍵面板中的tomcat v8.0…點(diǎn)擊start,開(kāi)啟服務(wù)器即可

在這里插入圖片描述

導(dǎo)入驅(qū)動(dòng)

導(dǎo)入的驅(qū)動(dòng)一定不能過(guò)高,最好和自己電腦mysql版本一致
我電腦上的mysql是5.5.53,用的驅(qū)動(dòng)是5.1.47,可用!

在這里插入圖片描述

鏈接: https://pan.baidu.com/s/1senUiVzre2B7It-TIdjO5w

提取碼: 5ksf

下載好解壓,直接將jar包拖入lib中,右鍵build path一下

在這里插入圖片描述

這樣就是導(dǎo)入成功!

修改代碼

找到我們創(chuàng)建的inc.jsp,修改下列代碼,以自己電腦為準(zhǔn),這個(gè)是和代碼相匹配的

在這里插入圖片描述

另外,所有web文件都要放在WEB-INF下

在這里插入圖片描述

連接mysql數(shù)據(jù)庫(kù)

連接名隨意,默認(rèn)端口為3306

在這里插入圖片描述

在數(shù)據(jù)庫(kù)中我們要?jiǎng)?chuàng)建一個(gè)數(shù)據(jù)庫(kù)庫(kù)名為demo,表名為users,
添加字段:username、password、email

在這里插入圖片描述

這就相當(dāng)于登陸的用戶(hù)名和密碼,可直接在數(shù)據(jù)庫(kù)中添加,也可通過(guò)注冊(cè)界面
填寫(xiě)注冊(cè)信息,同樣會(huì)顯示在數(shù)據(jù)庫(kù)中

運(yùn)行:

在這里插入圖片描述
在這里插入圖片描述

(1)login.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">
<html>
<head>
<base href="<%=basePath%>" rel="external nofollow" rel="external nofollow" rel="external nofollow" >

<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" rel="external nofollow" rel="external nofollow" rel="external nofollow" >
 -->
</head>

<body>
<form name="form1" action="login_action.jsp" method="post">
<table width="200" border="1">
	<tr>
		<td colspan="2">登錄窗口</td>
	<tr>
		<td>用戶(hù)名</td>
		<td><input type="text" name="username" size="10"></td>
	</tr>
	<tr>
		<td>密碼</td>
		<td><input type="password" name="password" size="10"></td>
	</tr>
	<tr>
		<td colspan="2"><input type="submit" name="submit" value="登錄"> <a
			href="register.jsp" rel="external nofollow" >注冊(cè)新用戶(hù)</a></td>
	</tr>
</table>
</form>

</body>
</html>
(2)login_action.jsp
<%@ page pageEncoding="utf-8" %>
<%@ include file="inc.jsp"%>
<%
//get parameters
String username = request.getParameter("username");
String password = request.getParameter("password");

//check null
if (username == null || password == null) {
	response.sendRedirect("login.jsp");
}

//validate
boolean isValid = false;
String sql = "select * from users where username='"+username+"' and password='"+password+"'";
try {
	Class.forName(drv).newInstance();
	Connection conn = DriverManager.getConnection(url, usr, pwd);
	Statement stm = conn.createStatement();
	ResultSet rs = stm.executeQuery(sql);
	if(rs.next())isValid = true;
	rs.close();
	stm.close();
	conn.close();
} catch (Exception e) {
	e.printStackTrace();
	out.println(e);
} finally {
}

if (isValid) {
	session.setAttribute("username", username);
	response.sendRedirect("welcome.jsp");
} else {
	response.sendRedirect("login.jsp");
}
%>
(3)register.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">
<html>
<head>
<base href="<%=basePath%>" rel="external nofollow" rel="external nofollow" rel="external nofollow" >

<title>My JSP 'register.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" rel="external nofollow" rel="external nofollow" rel="external nofollow" >
 -->
</head>

<body>
<form name="form1" action="register_action.jsp" method="post">
<table width="200" border="1">
	<tr>
		<td colspan="2">注冊(cè)窗口</td>
	<tr>
		<td>用戶(hù)名</td>
		<td><input type="text" name="username" size="10"></td>
	</tr>
	<tr>
		<td>密碼</td>
		<td><input type="password" name="password1" size="10"></td>
	</tr>
	<tr>
		<td>確認(rèn)密碼</td>
		<td><input type="password" name="password2" size="10"></td>
	</tr>
	<tr>
		<td>Email</td>
		<td><input type="text" name="email" size="10"></td>
	</tr>
	<tr>
		<td colspan="2"><input type="submit" name="submit" value="注冊(cè)"> <a
			href="login.jsp" rel="external nofollow" >返回</a></td>
	</tr>
</table>
</form>

</body>
</html>
(4)register_action.jsp
<%@ page pageEncoding="utf-8" %>
<%@ include file="inc.jsp"%>
<%
//get parameters
String username = request.getParameter("username");
String password1 = request.getParameter("password1");
String password2 = request.getParameter("password2");
String email = request.getParameter("email");


//check null
if (username == null || password1 == null || password2 == null || !password1.equals(password2)) {
	response.sendRedirect("register.jsp");
}


//validate
boolean isValid = false;
String sql = "select * from users where username='"+username+"'";
try {
	Class.forName(drv).newInstance();
	Connection conn = DriverManager.getConnection(url, usr, pwd);
	Statement stm = conn.createStatement();
	ResultSet rs = stm.executeQuery(sql);
	if(!rs.next()) {
		sql = "insert into users(username,password,email) values('"+username+"','"+password1+"','"+email+"')";
		stm.execute(sql);
		isValid = true;
	}
	
	rs.close();
	stm.close();
	conn.close();
} catch (Exception e) {
	e.printStackTrace();
	out.println(e);
}

if (isValid) {
	response.sendRedirect("login.jsp");
} else {
	response.sendRedirect("register.jsp");
}

%>
(5)welcome.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">
<html>
<head>
<base href="<%=basePath%>" rel="external nofollow" rel="external nofollow" rel="external nofollow" >

<title>My JSP 'welcome.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" rel="external nofollow" rel="external nofollow" rel="external nofollow" >
 -->
 <style type="text/css">
		
		body{
			background-color: beige;
		}
		</style>
</head>

<body>
<table width="100%">
	<tr>
		
		<td><img src="images/111.jpgA,LDYVS." height="90"></td>
	</tr>
	<tr>
		<td colspan="2">
		<hr>
		</td>
	</tr>
	<tr>
		<td>
		<table>
			<tr>
				<td><a href="welcome.jsp" rel="external nofollow" >Main</a></td>
			</tr>
			<tr>
				<td><a href="menu1.jsp" rel="external nofollow" >Menu1</a></td>
			</tr>
			<tr>
				<td><a href="menu2.jsp" rel="external nofollow" >Menu2</a></td>
			</tr>
			<tr>
				<td><a href="menu3.jsp" rel="external nofollow" >Menu3</a></td>
			</tr>
			<tr>
				<td><a href="menu4.jsp" rel="external nofollow" >Menu4</a></td>
			</tr>
			<tr>
				<td><a href="menu5.jsp" rel="external nofollow" >Menu5</a></td>
			</tr>
			<tr>
				<td><a href="menu6.jsp" rel="external nofollow" >Menu6</a></td>
			</tr>
			<tr>
				<td><a href="menu7.jsp" rel="external nofollow" >Menu7</a></td>
			</tr>
			<tr>
				<td><a href="menu8.jsp" rel="external nofollow" >Menu8</a></td>
			</tr>
		</table>
		</td>
		<td>
		<form name="form1" action="logout.jsp" method="post">
		<table width="200" border="1">
			<tr>
				<td colspan="2">登錄成功</td>
			<tr>
				<td>歡迎你,</td>
				<td><%=(String) session.getAttribute("username")%></td>
			</tr>
			<tr>
				<td colspan="2"><input type="submit" name="submit" value="退出"></td>
			</tr>
		</table>
		</form>
		</td>
	</tr>
</table>
</body>
</html> 
(6)logout.jsp
<%
session.removeAttribute("username");
response.sendRedirect("login.jsp");
%>
(7)inc.jsp
<%@ page import="java.sql.Connection"%>
<%@ page import="java.sql.DriverManager"%>
<%@ page import="java.sql.Statement"%>
<%@ page import="java.sql.ResultSet"%>
<%@ page import="java.sql.ResultSetMetaData"%>
<%
String drv = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
String url = "jdbc:sqlserver://localhost:1433;DatabaseName=Demo";
String usr = "sa";
String pwd = "";
%>

到此這篇關(guān)于eclipse連接數(shù)據(jù)庫(kù)并實(shí)現(xiàn)用戶(hù)注冊(cè)登錄功能的文章就介紹到這了,更多相關(guān)eclipse連接數(shù)據(jù)庫(kù)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Flyway詳解及Springboot集成Flyway的詳細(xì)教程

    Flyway詳解及Springboot集成Flyway的詳細(xì)教程

    Flayway是一款數(shù)據(jù)庫(kù)版本控制管理工具,,支持?jǐn)?shù)據(jù)庫(kù)版本自動(dòng)升級(jí),Migrations可以寫(xiě)成sql腳本,也可以寫(xiě)在java代碼里。這篇文章主要介紹了Flyway詳解及Springboot集成Flyway的詳細(xì)教程的相關(guān)資料,需要的朋友可以參考下
    2020-07-07
  • Java線(xiàn)程狀態(tài)轉(zhuǎn)換關(guān)系實(shí)例解析

    Java線(xiàn)程狀態(tài)轉(zhuǎn)換關(guān)系實(shí)例解析

    這篇文章主要介紹了Java線(xiàn)程狀態(tài)轉(zhuǎn)換關(guān)系實(shí)例解析,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-08-08
  • Java多線(xiàn)程基本概念以及避坑指南

    Java多線(xiàn)程基本概念以及避坑指南

    多線(xiàn)程之于進(jìn)程的理解,可以類(lèi)比多進(jìn)程之于操作系統(tǒng),多線(xiàn)程指在單個(gè)程序中可以同時(shí)運(yùn)行多個(gè)不同的線(xiàn)程執(zhí)行不同的任務(wù),這篇文章主要給大家介紹了關(guān)于Java多線(xiàn)程基本概念以及避坑指南的相關(guān)資料,需要的朋友可以參考下
    2021-09-09
  • Springboot配置security basic path無(wú)效解決方案

    Springboot配置security basic path無(wú)效解決方案

    這篇文章主要介紹了Springboot配置security basic path無(wú)效解決方案,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-09-09
  • Springboot實(shí)現(xiàn)高吞吐量異步處理詳解(適用于高并發(fā)場(chǎng)景)

    Springboot實(shí)現(xiàn)高吞吐量異步處理詳解(適用于高并發(fā)場(chǎng)景)

    這篇文章主要介紹了Springboot實(shí)現(xiàn)高吞吐量異步處理詳解(適用于高并發(fā)場(chǎng)景),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-11-11
  • IDEA中database使用教程

    IDEA中database使用教程

    idea集成了一個(gè)數(shù)據(jù)庫(kù)管理工具,可以可視化管理很多種類(lèi)的數(shù)據(jù)庫(kù),本文主要介紹了IDEA中database使用教程,具有一定的參考價(jià)值,感興趣的可以了解一下
    2023-06-06
  • 淺談hibernate中對(duì)象的3種狀態(tài)_瞬時(shí)態(tài)、持久態(tài)、脫管態(tài)

    淺談hibernate中對(duì)象的3種狀態(tài)_瞬時(shí)態(tài)、持久態(tài)、脫管態(tài)

    下面小編就為大家?guī)?lái)一篇淺談hibernate中對(duì)象的3種狀態(tài)_瞬時(shí)態(tài)、持久態(tài)、脫管態(tài)。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-08-08
  • 聊聊Spring循環(huán)依賴(lài)三級(jí)緩存是否可以減少為二級(jí)緩存的情況

    聊聊Spring循環(huán)依賴(lài)三級(jí)緩存是否可以減少為二級(jí)緩存的情況

    這篇文章主要介紹了聊聊Spring循環(huán)依賴(lài)三級(jí)緩存是否可以減少為二級(jí)緩存的情況,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2021-02-02
  • JavaWeb實(shí)現(xiàn)簡(jiǎn)單的自動(dòng)登錄功能

    JavaWeb實(shí)現(xiàn)簡(jiǎn)單的自動(dòng)登錄功能

    這篇文章主要為大家詳細(xì)介紹了JavaWeb實(shí)現(xiàn)簡(jiǎn)單的自動(dòng)登錄功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-08-08
  • java調(diào)用短信貓發(fā)短信示例

    java調(diào)用短信貓發(fā)短信示例

    這篇文章主要介紹了java調(diào)用短信貓發(fā)短信示例,需要的朋友可以參考下
    2014-04-04

最新評(píng)論

左云县| 平江县| 阜阳市| 太康县| 金堂县| 广饶县| 湄潭县| 自贡市| 涿州市| 玉龙| 堆龙德庆县| 武宁县| 高唐县| 南汇区| 锡林郭勒盟| 环江| 清徐县| 剑河县| 冷水江市| 肇州县| 蒙山县| 肥乡县| 夹江县| 梨树县| 沾化县| 永胜县| 桦甸市| 大姚县| 嘉祥县| 区。| 纳雍县| 阿鲁科尔沁旗| 镇原县| 衡东县| 三台县| 乐平市| 桑植县| 贵港市| 日土县| 永年县| 威宁|