JSP实现用户登录、注册和退出成果(2)

利用JDBC毗连数据库,假如用户名或暗码为空时,照旧跳转到登录页面login.jsp
假如用户名和暗码不为空,举办毗连数据库查询用户表,假如可以或许查询到记录,暗示登录乐成,将用户信息生存到session,跳转到接待页面welcome.jsp

假如按照用户名和暗码查询不到记录,暗示登录失败,从头跳转到登录页面login.jsp

4.3接待页面

welcome.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"https://www.jb51.net/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="https://www.jb51.net/<%=basePath%>"> <title>My JSP 'welcom.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 type="text/css" href="https://www.jb51.net/styles.css"> --> </head> <body> <table> <tr> <td><img src="https://www.jb51.net/images/logo4.png" /> </td> <td><img src="https://www.jb51.net/images/logo2.png" /> </td> </tr> <tr> <td colspan="2"><hr /> </td> </tr> <tr> <td> <table> <tr> <td><a>Main</a> </td> </tr> <tr> <td><a>Menu1</a> </td> </tr> <tr> <td><a>Menu2</a> </td> </tr> <tr> <td><a>Menu3</a> </td> </tr> <tr> <td><a>Menu4</a> </td> </tr> <tr> <td><a>Menu5</a> </td> </tr> <tr> <td><a>Menu6</a> </td> </tr> <tr> <td><a>Menu7</a> </td> </tr> <tr> <td><a>Menu8</a> </td> </tr> </table></td> <td> <form action="loginout.jsp" method="post"> <table> <tr> <td colspan="2">登录乐成!</td> </tr> <tr> <td>接待你,</td> <td>${username }</td> </tr> <tr> <td colspan="2"><input type="submit" value="退出" /></td> </tr> </table> </form></td> </tr> </table> </body> </html>

利用EL表达式展示用户信息

结果

JSP实现用户登录、注册和退出成就

4.4接待页退出逻辑处理惩罚页面

loginout.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"https://www.jb51.net/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="https://www.jb51.net/<%=basePath%>"> <title>My JSP 'loginout.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 type="text/css" href="https://www.jb51.net/styles.css"> --> </head> <body> <% session.removeAttribute("username"); response.sendRedirect("https://www.jb51.net/login.jsp"); %> </body> </html>

将session的用户信息移除,跳转到登录页面login.jsp

4.5注册页面

register.jsp

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wsddxf.html