JSP的指令与动作(续)

(一)三条指令
<%@page %>
<%@include file=" “%> 静态包含 编译之前
<%@taglib url=” “%>
(二)七个动作中的三个动作
<jsp:include page=’’ " flush=“ture”></jsp:include>
<jsp:forward page=” " ></jsp:forward>
ps:页面的跳转:客户端跳转: 表单提交
服务器端的跳转:jsp:forword
<jsp:param name="" value=""/>在被包含的文件和服务器段跳转的页面之间传递参数,只能作为子标签使用。
动作 案例
main.jsp 展示页面

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>

<%
String file="top.jsp";
String name="Tom";
%>
<jsp:include page="top.jsp"  flush="true">
<jsp:param value="<%=name %>" name="x"></jsp:param>

</jsp:include>

<p>页面部分</p>
<%-- <jsp:include page="bottom.jsp" >

</jsp:include>
 --%>

<a href="../jiaohu.jsp">返回首页面</a>
</body>
</html>

top.jsp

<%@ page language="java" contentType="text/html; charset=gb2312"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>

<%
String name= request.getParameter("x");%>
<p>页面头部部分</p>
<%=name %>
</body>
</html>

结果输出name为tom.
用户登录页面案例

<%@page contentType="text/html;charset=gb2312"%>
<html>
<head>
	<title>登陆</title>
</head>
<body>
<center>
	<h1>用户名及密码固定</h1>
	<hr>
	<br>
	<br>
	
	<table>
		<tr>
			<td colspan="2">用户登陆</td>
		</tr>
		<tr>
			<td>用户名:</td>
			<td><input type="text" name="uname"></td>
		</tr>
		<tr>
			<td>&nbsp;&nbsp;码:</td>
			<td><input type="password" name="upassword"></td>
		</tr>
		<tr>
			<td colspan="2">
			<input type="submit" value="登陆">
			<input type="reset" value="重置">
			</td>
		</tr>
	</table>
	</form>
</center>
</body>
</html>
	<title>登陆</title>
</head>
<body>
<center>
	<h1>用户名及密码固定</h1>
	<hr>
	<br>
	<br>
	<%
		// 接收请求的内容
		String name = request.getParameter("uname") ;
		String password = request.getParameter("upassword") ;

		// System.out.println(name) ;
		// System.out.println(password) ;
	%>
	<%
		// 判断用户名及密码
		// if("lulu"==name&&"123456"==password)
		if("lulu".equals(name)&&"123456".equals(password))		
		{
			// 合法用户
	%>
			<jsp:forward page="login_success.jsp"/>
	<%
		}
		else
		{
			// 非法用户
	%>
			<jsp:forward page="login_failure.jsp"/>
	<%
		}
	%>
</center>
</body>
</html>

成功页面

<html>
<head>
	<title>登陆</title>
</head>
<body>
<center>
	<h2>用户名及密码固定</h2>
	<hr>
	<br>
	<br>
	<h2>登陆成功</h2>
	<h3>欢迎<font color="red" size="15">
		<%=request.getParameter("uname")%>
	</font>光临!!!</h3>
</center>
</body>
</html>

失败页面

<%@page contentType="text/html;charset=gb2312"%>
<html>
<head>
	<title>登陆</title>
</head>
<body>
<center>
	<h2>用户名及密码固定</h2>
	<hr>
	<br>
	<br>
	<h2>登陆失败</h2>
	<h3>错误的用户名及密码!!!</h3>
	<a href="login.jsp">重新登陆</a>
</center>
</body>
</html>
                  

结果展示
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值