JSP实现简单的登录页面实现及代码(非连接数据库)

**

JSP实现简单的登录页面实现及代码(非连接数据库)

**
1、实现一个简单的登陆页面;
2、如果登陆成功,提示页面欢迎你,进入我的主页;
3、如果登陆不成功跳转到登陆页面;
4、使用固定用户名和密码即可。

jsp文件目录
总共分为五块内容
在这里插入图片描述
1. login.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>欢迎登陆!</title>
</head>
<body>
<%--登录页面 --%>
<h1 style="text-align:center;">欢迎登录!</h1>
<form action="loginProcess.jsp">
<table align="center" border="10">
<tr>
<td>用户名:</td>
<td><input type="text" name="user"></td>
</tr>
<tr>
<td>密    码:</td>
<td><input type="password" name="password"></td>
</tr>
<tr>
<td>确认密码:</td>
<td><input type="password" name="password2"></td>
</tr>
<tr>
<td><input type="submit" name="提交"></td>
<td><input type="reset" name="重置"></td>
</tr>
</table>
</form>
 
</body>
</html>

2. loginProcess.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>登录处理</title>
</head>
<body>
<%--登录处理 --%>
<%
request.setCharacterEncoding("UTF-8");
String name=request.getParameter("user");
String password=request.getParameter("password"); 
String password2=request.getParameter("password");
%>
    <% if("kongjunjie".equals(name) && "1701110273".equals(password) && (password==password2) )
	{
	%>
       <jsp:forward page="success.jsp"></jsp:forward>
    <%
	}
	else
	{
	%>
       <jsp:forward page="error.jsp"></jsp:forward>
	<%
	}
	%>

</body>
</html>

3. success.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>登录成功,跳转到主页</title>
</head>
<body>
<%--登录成功,进入我的主页 --%>
<h1><%=request.getParameter("user")%>恭喜你登录成功!!!</h1><br>
<h1><a href="homepage.jsp">点击进入我的主页</a></h1>
</body>
</html>

4.homepage.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>我的主页</title>
</head>
<body>
<%--我的主页 --%>
<h1>这里是我的主页,欢迎你!!!</h1>
</body>
</html>

5. error.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>登录错误</title>
</head>
<body>
<%--登录出错 --%>
<h1>登录信息输入错误,请重新输入!</h1><br>
<h1><a href="login.jsp">点击进入登录页面</a></h1>
</body>
</html>

运行结果:
在这里插入图片描述

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值