首先要知道的是:
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>
可以自己改变分数,然后输出不同成绩的不同提示信息