JSP forward用法分析实例代码分析

发布时间:2022-04-17 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了JSP forward用法分析实例代码分析脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
1.首页(填写姓名)(可选,表单post到time.jsp即可):

2.判断时间forward到不同页面:
time.jsp:
复制代码 代码如下:

<%--
Document : index
Created on : 2009-10-3, 15:48:00
Author : lucifer
--%>
<%@page contentTyPE="text/htML" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PubLIC "-//W3C//DTD HTML 4.01 TransITional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%@page import="java.util.Date" %>
<html>
<head>
<;meta http-equiv="Content-type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<%
Date dat =
new Date();
if(dat.getHours() <= 12){
%>
<jsp:forward page="amGreeting.jsp"/>
<%}
else{
%>
<jsp:forward page="PmGreeting.jsp"/>
<%}
%>
</body>
</html>

3.如果是早上:
AmGreeting.jsp:
复制代码 代码如下:

<%--
Document : AmGreeting
Created on : 2009-10-3, 16:00:10
Author : lucifer
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>Good Morning! </h1>
<%
String name = request.getParameter("userName");
out.PRintln(name);
%>
!!!
</body>
</html>

如果是下午:
PmGreeting.jsp:
复制代码 代码如下:

<%--
Document : AmGreeting
Created on : 2009-10-3, 16:00:10
Author : lucifer
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>Good Afternoon! </h1>
<%
String name = request.getParameter("userName");
out.println(name);
%>
!!!
</body>
</html>

脚本宝典总结

以上是脚本宝典为你收集整理的JSP forward用法分析实例代码分析全部内容,希望文章能够帮你解决JSP forward用法分析实例代码分析所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签:JSP