欢迎来到ST小哥的博客

JSP登录验证注册界面

简单的JSP登录验证注册界面

*基于eclipse+apache tomcat 8.5 编写的简单认证判断登录和显示信息。

**完成简单逻辑判断,对结果输出

***JSP基础练习登录

 

 登陆界面

index.jsp

 1 <%@ page language="java" contentType="text/html; charset=UTF-8"
 2     pageEncoding="UTF-8"%>
 3 <!DOCTYPE html>
 4 <html>
 5 <head>
 6 <meta charset="UTF-8">
 7 <title>登陆界面</title>
 8 
 9 </head>
10 <body>
11 <h2 style="text-align:lift;">注册新用户</h2>
12 <hr>
13 <form action="dealwith.jsp">
14 <table align="center" border="1">
15 <tr>
16 <td style="background-color: gray;">用户名:</td>
17 <td><input type="text" name="user" > *【检测用户】</td>
18 </tr>
19 <tr>
20 <td style="background-color: gray;">密码:</td>
21 <td><input type="password" name="password">*【需6-20内的字符】</td>
22 </tr>
23 <tr>
24 <td style="background-color: gray;">确认密码:</td>
25 <td><input type="password" name="password_again">*</td>
26 </tr>
27 <tr>
28 <td style="background-color: gray;">性别:</td>
29 <td><input type="radio" value="男" checked="checked" name="boy"><input type="radio" value="女s" ></td>
30 </tr>
31 <tr>
32 <td style="background-color: gray;">学历:</td>
33 <td><select name="xueli">
34 <option >大专</option>
35 <option >本科</option>
36 </select></td>
37 </tr>
38 <tr>
39 <td style="background-color: gray;"></td>
40 <td style="background-color: gray;"><input style="margin-left: 20%;" type="submit" value="注册"><input style="margin-left: 20%;" type="reset" value="重置"></td>
41 </tr>
42 </table>
43 </form>
44 </body>
45 <footer align="center">@ST</footer>
46 </html>

 

在第一个的基础上编写逻辑dealwith.jsp页面,如果用户名或密码为空,则使用forward动作标记跳转到error.jsp页面,页面输出“请输入用户名与密码,谢谢!”如果用户名和密码均不为空,则使用forward动作标记跳转到success.jsp页面,把前面用户输入的信息显示出来。

判断界面

 dealwith.jsp

 1 <%@ page language="java" contentType="text/html; charset=UTF-8"
 2     pageEncoding="UTF-8"%>
 3 <!DOCTYPE html>
 4 <html>
 5 <head>
 6 <meta charset="UTF-8">
 7 <title>登录处理</title>
 8 </head>
 9 <body>
10 <%
11 request.setCharacterEncoding("UTF-8");
12 String name=request.getParameter("user");
13 String password=request.getParameter("password"); 
14 String password2=request.getParameter("password_again");
15 %>
16 <% if( "" == name || "" == password)
17     {
18     %>
19        <jsp:forward page="error.jsp"></jsp:forward>
20     <%
21     }
22     else
23     {
24     %>
25        <jsp:forward page="success.jsp"></jsp:forward>
26     <%
27     }
28     %>
29 </body>
30 </html>

判定错误

error.jsp

 1 <%@ page language="java" contentType="text/html; charset=UTF-8"
 2     pageEncoding="UTF-8"%>
 3 <!DOCTYPE html>
 4 <html>
 5 <head>
 6 <meta charset="UTF-8">
 7 <title>错误</title>
 8 </head>
 9 <body>
10 <h1 align="center">请输入用户名与密码,谢谢!</h1>
11 <h2 align="center"><a href="index.jsp">点击重新进入登录页</a></h2>
12 </body>
13 </html>

 

判定成功

 success.jsp

 1 <%@ page language="java" contentType="text/html; charset=UTF-8"
 2     pageEncoding="UTF-8"%>
 3 <!DOCTYPE html>
 4 <html>
 5 <head>
 6 <meta charset="UTF-8">
 7 <title>成功!</title>
 8 </head>
 9 <body>
10 <h1 align="center">用户:<%=request.getParameter("user")%>恭喜你登录成功!!!</h1><br>
11 <h2 align="center">当前用户:<%=request.getParameter("user")%><br>
12                     密码:<%=request.getParameter("password")%><br>
13                     性别:<%=request.getParameter("boy")%><br>
14                     学历:<%=request.getParameter("xueli")%> </h2>
15 <h3 align="center"><a href="index.jsp">点击重新进入登录页</a></h3>
16 </body>
17 </html>

 

最后要说:1.链接页面修改名字要记得在跳转处同步修改

     2.index.jsp中的name需要命名,否则后面显示不出来

 

posted @ 2022-03-09 14:17  Steven_Tim  阅读(1871)  评论(0编辑  收藏  举报