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/

你可能感兴趣的:(request对象的使用)