JSP forward用法分析实例代码分析
程序员文章站
2023-11-26 19:59:58
1.首页(填写姓名)(可选,表单post到time.jsp即可): 略 2.判断时间forward到不同页面: time.jsp: 复制代码 代码如下: <%-- d...
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>
略
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>