Web-jsp第三次作业

用JSP实现用户登录验证的功能。

一.第一个程序

1.第一个页面 登录注册框

<%@ 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>Insert title here</title>
</head>
<body>
<form id = "form1" name = "form1" method = "post" action = "5-5-2.jsp">
<ul style="list-style:none">
<li>账号:<input name = "account" type = "text"/></li>
<li>密码:<input name = "password" type = "password"/></li>
<div style="text-align:left">
    <li><input name = "Submit" type = "submit" value = "登录"/></li>
</div>
</ul>
</form>
</body>
</html>

2.第二个页面,检测账号密码是否有效。若符合条件则弹出获取到的账号,密码;反之跳出“您输入的账号密码有误,请重新输入! ”的提示语句。

这里设置账号为“yyy”,密码为“111”。

<%@ 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>Insert title here</title>
</head>
<body>
<%
String account = request.getParameter("account");
String password = request.getParameter("password");
 
if(account.equals("yyy") || password.equals("111"))
{
    out.print("您输入的账号密码有误,请重新输入!");
    %>
<form id = "form1" name = "form1" method = "post" action = "5-5-3.jsp">
<ul style="list-style:none">
<li>账号:<input name = "account" type = "text"/></li>
<li>密码:<input name = "password" type = "password"/></li>
<div style="text-align:left">
    <li><input name = "Submit" type = "submit" value = "登录"/></li>
</div>
</ul>
</form>
<%
}
else
{
    out.print("您好," + account + "!");
    %>
<form>
<ul style = "list-style:none">
<li>账号:<%= account %></li>
<li>密码:<%= password %></li>
</ul>
</form>
<%
}
%>
</body>
</html>

效果图:

二.第二个页面

  1. 第一个页面,登录输入密码界面。

<%@ 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>Insert title here</title>
</head>
<body>
<form id = "form1" name = "form1" method = "post" action = "5-5-4.jsp">
<ul style="list-style:none">
<li>账号:<input name = "account" type = "text"/></li>
<li>密码:<input name = "password" type = "password"/></li>
<div style="text-align:left">
    <li><input name = "Submit" type = "submit" value = "登录"/></li>
</div>
</ul>
</form>
</body>
</html>
  1. 第二个页面,判断是否符合登录条件。若账号和密码输入为空,则点击登录按钮,出现“非法访问”;若符合条件,则跳出“欢迎您”。

<%@ 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>Insert title here</title>
</head>
<body>
<%
String account = request.getParameter("account");
String password = request.getParameter("password");
 
if(account.equals("") && password.equals(""))
{
    out.print("欢迎你, null" + "<br>");
    out.print("非正常访问");
}
else
{
    out.print("您好," + account + "!" + "<br>");
    out.print("账号:" + account + "<br>");
    out.print("密码:" + password);
}
%>
</body>
</html>

效果图:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值