Hello JSP!——内置对象基础练习题

一、一个简单的用户登录案例

LoginForm.jsp

<%@ page language="java" contentType="text/html;charset=gb2312"%>
<html>
	<head>
		<title>用户登录</title>
	</head>
	<body>
		<center>
			<form action = "LoginConf.jsp" method="post">
				<table>
					<tr>
						<td colspan="2">用户登录</td>
					</tr>
					<tr>
						<td>用户名:</td>
						<td><input type="text" name="username"></td>
					</tr>
					<tr>
						<td>密  码:</td>
						<td><input type="password" name="userpassword"></td>
					</tr>
					<tr>
						<td colspan="2">
						<input type="submit" value="登录">
						<input type="reset" value="重置">
						</td>
					</tr>	
				</table>
			</form>
		</center>
	</body>
</html>

LoginConf.jsp

<%@ page language="java" contentType="text/html; charset=gb2312"%>
<html>
	<head>
		<title>登录判断</title>
	</head>
	<body>
		<center>
			<%
				String username = request.getParameter("username"); //接收用户名参数
				
				String userpassword = request.getParameter("userpassword"); //接收用户密码参数
			 %>
			 <%
			 	//判断用户名及密码,如果为指定用户则跳转到登录成功页面
			 	if ("James".equals(username) && "1234".equals(userpassword)){
			  %>
			  <jsp:forward page = "LoginSuccess.jsp"/>
			  <% 
			  	}
			  	//如果不是指定用户则跳转到登录失败页面
			  	else {
			   %>
			   <jsp:forward page = "LoginFailure.jsp"/>
			   <%
			   		 }
			    %>
		</center>
	</body>
</html>

LoginSuccess.jsp

<%@ page language="java" contentType="text/html;charset=gb2312"%>
<html>
	<head>
		<title>登录成功</title>
	</head>
	<body>
		<center>
			<h1>登录成功</h1>
		</center>
	</body>
</html>

LoginFailure.jsp

<%@ page language="java" contentType="text/html;charset=gb2312"%>
<html>
	<head>
		<title>登录失败</title>
	</head>
	<body>
		<center>
			<h1>登录失败</h1>
		</center>
	</body>
</html>

运行结果:





二、填空。

1.与Servlet有关的内置对象,包括   page   config  两个内置对象。


2.JSP中提供了4种属性保存范围,分别为  page  request    session     application


3.通过request对象的getParameter(String name)方法,可以获得参数名为name的参数值。


4.通过response对象的sendRedirect(URL)方法设置页面重定向,从而实现页面跳转。


5.通过out对象的print(String str)方法和println(String str)方法进行页面输出。


6.通过session对象的setMaxInactiveInterval()方法设置session生命周期,通过getMaxInactiveInterval()方法获得session生命周期。



评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值