request对象的使用

index.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>
<style type="text/css">
	li{list-style: none;}
</style>
</head>

<body>
	<div>
		<form action="login.jsp" method="post">
			<ul>
				<li><h3>用户登录</h3></li>
			</ul>
			<ul>
				<li>用户名:<input type="text" name="username"></li>
			</ul>
			<ul>
				<li>密 码:<input type="password" name="password"></li>
			</ul>
			<ul>
				<li>
					<input type="submit" value="登 录">
				</li>
			</ul>
		</form>
	</div>
</body>
</html>

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>Insert title here</title>
</head>
<body>
<%
	// 获取用户名
	String username = request.getParameter("username");
	// 获取密码
	String password = request.getParameter("password");
	// 判断用户名与密码的值是否为"admin"
	if("admin".equals(username) && "admin".equals(password)){
		// 登录成功
		out.print("<h3>恭喜,登录成功!</h3>");
	}else{
		// 登录失败
		out.print("<h3>对不起,登录失败!</h3>");
	}
%>
</body>
</html>

运行效果http://115.29.139.162:8080/WebContent/010/

转载于:https://my.oschina.net/ahthw/blog/271010

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值