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生命周期。



  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
简易聊天室本次实验的目的是通过以下题目掌握JSP内置对象,包括:request,response,session,application等。 (1)制作简易聊天室,能够实现简单的页面聊天功能。 (2)制作网页计数器,要求相同的窗口内刷新页面访问次数并不增加,并且用图片来显数字。1、 熟悉request、response、session、application、out等内置对象; 2、 选择制作网页计数器程序需准备数字图片;1、进入jsp子目录,编写简易聊天室JSP程序,聊天室的需要实现的基本功能:输入昵称、聊天。 2.根据功能编写页面代码。二、网页计算器 利用内置对象application <html> <head> <base href="<%=basePath%>"> <title>My JSP 'Counter.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> --> </head> <body> 您是第位访问者! </body> </html> 简易聊天室本次实验的目的是通过以下题目掌握JSP内置对象,包括:request,response,session,application等。 (1)制作简易聊天室,能够实现简单的页面聊天功能。 (2)制作网页计数器,要求相同的窗口内刷新页面访问次数并不增加,并且用图片来显数字。1、 熟悉request、response、session、application、out等内置对象; 2、 选择制作网页计数器程序需准备数字图片;1、进入jsp子目录,编写简易聊天室JSP程序,聊

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值