jsp中forward跳转实现不同成绩跳转到不同页面

首先要知道的是:
forward跳转是立即跳转,一旦执行了forward跳转,立刻跳到另一个页面,原本页面下面的内容不会执行

<%@ 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>

<%
	int s = 48;//分数
	if(s>=90){%>
		<jsp:forward page="_a6_forward跳转_不同成绩不同输出good.jsp">
			<jsp:param value="<%=s %>" name="score"/>
		</jsp:forward>
	<% }else if (s<60){%>
		<jsp:forward page="_a6_forward跳转_不同成绩不同输出bad.jsp">
			<jsp:param value="<%=s %>" name="score"/>	
		</jsp:forward>
	<% }
%>

成绩已经核对完成.<!-- 这句话不执行,说明forward跳转是立即跳转 -->

</body>
</html>

_a6_forward跳转_不同成绩不同输出good.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 s = request.getParameter("score");
	int sc = Integer.parseInt(s);
%>

<h2>成绩考的很不错,你竟然考了<%=sc %>分,是不是抄的人家的?还是考试作弊了?</h2>

</body>
</html>

_a6_forward跳转_不同成绩不同输出bad.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 s = request.getParameter("score");
	int sc = Integer.parseInt(s);
%>

<h2>成绩考的可不好,你才考了<%=sc %>分,你会作弊也行啊,孺子不可教也</h2>

</body>
</html>

在这里插入图片描述
可以自己改变分数,然后输出不同成绩的不同提示信息

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

爱睡觉的小馨

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值