使用JSP實(shí)現(xiàn)簡(jiǎn)單的用戶登錄注冊(cè)頁(yè)面示例代碼解析
實(shí)驗(yàn)要求:
將實(shí)驗(yàn)2中的系統(tǒng)用戶登錄和注冊(cè)頁(yè)面改為JSP頁(yè)面,并部署自己的Web應(yīng)用于Tomcat服務(wù)器中
具體要求:
完成登錄JSP頁(yè)面設(shè)計(jì)和注冊(cè)頁(yè)面設(shè)計(jì)
在登錄頁(yè)面表單中使用request對(duì)象獲取用戶信息,建立新的JSP頁(yè)面完成登錄驗(yàn)證(用戶名和密碼自己指定即可)。
驗(yàn)證結(jié)果顯示(如登錄成功/用戶名密碼錯(cuò)誤,可以使用JavaScript,也可以使用新的JSP頁(yè)面)。
在注冊(cè)頁(yè)面表單中使用request對(duì)象獲取用戶注冊(cè)信息(注冊(cè)項(xiàng)目由自己指定),在新的JSP頁(yè)面顯示用戶注冊(cè)信息,并提示注冊(cè)成功。
代碼
登錄頁(yè)面index.html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>jsp作業(yè)</title>
<link href="css/bootstrap.min.css" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="stylesheet">
</head>
<body>
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="./" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >jsp作業(yè)</a>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
<li><a href="login.jsp" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >登錄</a></li>
</ul>
</div>
</div>
</nav>
<div class="container">
<div class="jumbotron">
<h1>Hello, world!</h1>
<p>這是一個(gè)jsp作業(yè)</p>
</div>
</div>
</body>
</html>
登錄頁(yè)面login.jsp
<%@ page contentType="text/html; charset=utf-8" language="java"%>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>登錄</title>
<link href="css/bootstrap.min.css" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="stylesheet">
</head>
<body>
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="./" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >jsp作業(yè)</a>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
<li><a href="login.jsp" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >登錄</a></li>
</ul>
</div>
</div>
</nav>
<div class="container">
<div class="row">
<div class="col-md-4">
</div>
<div class="col-md-4">
<form class="form-signin" method="post" action="login-check.jsp">
<h2 class="form-signin-heading">登錄到j(luò)sp作業(yè)</h2>
<label for="">用戶名</label>
<input type="text" name="username" id="username" class="form-control" placeholder="請(qǐng)輸入用戶名" required autofocus><br>
<label for="">密碼</label>
<input type="password" name="password" id="password" class="form-control" placeholder="請(qǐng)輸入密碼" required>
<div class="checkbox">
<label>
<input type="checkbox" value="remember-me" checked="checked"> 記住密碼
</label>
</div>
<button type="submit" class="btn btn-primary" id="btn-login">登錄</button>
<a href="reg.jsp" rel="external nofollow" rel="external nofollow" class="btn btn-default">注冊(cè)</a>
</form>
</div>
<div class="col-md-4">
</div>
</div>
</body>
</html>
登錄結(jié)果頁(yè)面login-check.jsp
<%@ page contentType="text/html; charset=utf-8" language="java"%>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>登錄</title>
<link href="css/bootstrap.min.css" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="stylesheet">
</head>
<body>
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="./" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >jsp作業(yè)</a>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
<li><a href="login.jsp" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >登錄</a></li>
</ul>
</div>
</div>
</nav>
<div class="container">
<div class="row">
<div class="col-md-4">
</div>
<div class="col-md-4">
<form class="form-signin" method="post" action="login-check.jsp">
<h2 class="form-signin-heading">登錄到j(luò)sp作業(yè)</h2>
<label for="">用戶名</label>
<input type="text" name="username" id="username" class="form-control" placeholder="請(qǐng)輸入用戶名" required autofocus><br>
<label for="">密碼</label>
<input type="password" name="password" id="password" class="form-control" placeholder="請(qǐng)輸入密碼" required>
<div class="checkbox">
<label>
<input type="checkbox" value="remember-me" checked="checked"> 記住密碼
</label>
</div>
<button type="submit" class="btn btn-primary" id="btn-login">登錄</button>
<a href="reg.jsp" rel="external nofollow" rel="external nofollow" class="btn btn-default">注冊(cè)</a>
</form>
</div>
<div class="col-md-4">
</div>
</div>
</body>
</html>
注冊(cè)頁(yè)面reg.jsp
<%@ page contentType="text/html; charset=utf-8" language="java"%>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>注冊(cè)</title>
<link href="css/bootstrap.min.css" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="stylesheet">
</head>
<body>
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="./" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >jsp作業(yè)</a>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
<li><a href="login.jsp" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >登錄</a></li>
</ul>
</div>
</div>
</nav>
<div class="container">
<div class="row">
<div class="col-md-4">
</div>
<div class="col-md-4">
<form class="form-signin" action="reg-submit.jsp" method="post">
<h2 class="form-signin-heading">注冊(cè)到j(luò)sp作業(yè)</h2>
<div id="info">
</div>
<label for="">用戶名</label>
<input type="text" name="username" id="username" class="form-control" placeholder="請(qǐng)輸入用戶名" required autofocus><br>
<label for="">密碼</label>
<input type="password" name="password" id="password" class="form-control" placeholder="請(qǐng)輸入密碼" required><br>
<label for="">重復(fù)密碼</label>
<input type="password" name="password2" id="password2" class="form-control" placeholder="請(qǐng)?jiān)俅屋斎朊艽a" required maxLength="16"><br>
<button type="submit" class="btn btn-primary" id="btn-reg">注冊(cè)</button>
<a href="login.jsp" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="btn btn-default" id="btn-reg">返回登錄</a>
</form>
</div>
<div class="col-md-4">
</div>
</div>
</body>
</html>
注冊(cè)結(jié)果頁(yè)面reg-submit.jsp
<%@ page contentType="text/html; charset=utf-8" language="java"%>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>結(jié)果</title>
<link href="css/bootstrap.min.css" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="stylesheet">
</head>
<body>
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="./" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >jsp作業(yè)</a>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
<li><a href="login.jsp" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >登錄</a></li>
</ul>
</div>
</div>
</nav>
<div class="container">
<% String username = request.getParameter("username");
String password = request.getParameter("password");
String password2 = request.getParameter("password2");
%>
<%
if(password.equals(password2)){
out.println("<div class='alert alert-success' role='alert'>注冊(cè)成功</div>");
out.println("<ul class='list-group'>");
out.println("<li class='list-group-item'>用戶名:" + username + "</li>");
out.println("<li class='list-group-item'>密碼:" + password + "</li>");
out.println("</ul>");
}
else{
out.println("<div class='alert alert-danger' role='alert'>兩次密碼輸入不一致,請(qǐng)重新輸入</div>");
}
%>
<!-- <%=username %>
<%=password %>
<%=password2 %> -->
</div>
效果





到此這篇關(guān)于使用JSP實(shí)現(xiàn)簡(jiǎn)單的用戶登錄注冊(cè)頁(yè)面示例代碼解析的文章就介紹到這了,更多相關(guān)JSP實(shí)現(xiàn)簡(jiǎn)單的用戶登錄注冊(cè)頁(yè)面內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
jsp+servlet+jdbc實(shí)現(xiàn)對(duì)數(shù)據(jù)庫(kù)的增刪改查
本篇文章主要介紹了jsp+servlet+jdbc實(shí)現(xiàn)對(duì)數(shù)據(jù)庫(kù)的增刪改查,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-01-01
jsp+servlet+javabean實(shí)現(xiàn)數(shù)據(jù)分頁(yè)方法完整實(shí)例
這篇文章主要介紹了jsp+servlet+javabean實(shí)現(xiàn)數(shù)據(jù)分頁(yè)方法,以完整實(shí)例形式詳細(xì)講述了jsp結(jié)合servlet與javabean操作PostgreSQL數(shù)據(jù)庫(kù)實(shí)現(xiàn)分頁(yè)的具體步驟,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-11-11
JSP自定義標(biāo)簽Taglib實(shí)現(xiàn)過(guò)程重點(diǎn)總結(jié)
Taglib指令,其實(shí)就是定義一個(gè)標(biāo)簽庫(kù)以及自定義標(biāo)簽的前綴,其中的具體的實(shí)現(xiàn)方式,我們不過(guò)多介紹,我們給大家從宏觀的角度以及解決其中的疑難點(diǎn),感興趣的朋友可以了解下,或許對(duì)你學(xué)習(xí)jsp有所幫助2013-02-02
jsp利用echarts實(shí)現(xiàn)報(bào)表統(tǒng)計(jì)的實(shí)例
echarts用來(lái)做數(shù)據(jù)報(bào)表的一個(gè)展示效果了,本文介紹了jsp利用echarts實(shí)現(xiàn)報(bào)表統(tǒng)計(jì)的實(shí)例,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下。2016-10-10
JSP開(kāi)發(fā)之生成圖片驗(yàn)證碼技術(shù)的詳解
這篇文章主要介紹了JSP開(kāi)發(fā)之生成圖片驗(yàn)證碼技術(shù)的詳解的相關(guān)資料,希望通過(guò)本文能幫助到大家實(shí)現(xiàn)圖片驗(yàn)證碼技術(shù),需要的朋友可以參考下2017-09-09
如何在Jsp中使用JDBC來(lái)聯(lián)結(jié)MySql
如何在Jsp中使用JDBC來(lái)聯(lián)結(jié)MySql...2006-10-10
解決request.getParameter取值后的if判斷為NULL的問(wèn)題
這篇文章主要介紹了解決request.getParameter取值后的if判斷為NULL的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-03-03
JSP開(kāi)發(fā)入門(二)----JSP語(yǔ)法的基本原理
JSP開(kāi)發(fā)入門(二)----JSP語(yǔ)法的基本原理...2006-10-10

