JSP forward用法分析實(shí)例代碼分析
更新時(shí)間:2009年10月04日 15:40:50 作者:
JSP forward用法分析,需要的朋友可以參考下。
1.首頁(yè)(填寫(xiě)姓名)(可選,表單post到time.jsp即可):
略
2.判斷時(shí)間forward到不同頁(yè)面:
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.判斷時(shí)間forward到不同頁(yè)面:
time.jsp:
復(fù)制代碼 代碼如下:
<%--
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:
復(fù)制代碼 代碼如下:
<%--
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:
復(fù)制代碼 代碼如下:
<%--
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>
相關(guān)文章
jsp倒計(jì)時(shí)簡(jiǎn)單實(shí)現(xiàn)方法
這篇文章主要介紹了jsp倒計(jì)時(shí)簡(jiǎn)單實(shí)現(xiàn)方法,涉及Java時(shí)間運(yùn)算與顯示的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-10-10Jsp頁(yè)面實(shí)現(xiàn)文件上傳下載類代碼
2008-01-01JSP自定義標(biāo)簽基礎(chǔ)知識(shí)學(xué)習(xí)
這篇文章主要為大家詳細(xì)介紹了JSP自定義標(biāo)簽基礎(chǔ)知識(shí),如何實(shí)現(xiàn)自定義標(biāo)簽,請(qǐng)參考本文進(jìn)行學(xué)習(xí)2016-03-03img的src地址是一個(gè)請(qǐng)求的方式來(lái)顯示圖片方法
下面小編就為大家?guī)?lái)一篇img的src地址是一個(gè)請(qǐng)求的方式來(lái)顯示圖片方法。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-03-03asp.net getRemoteAddr()與 getRemoteHost()的區(qū)別
getRemoteAddr()與 getRemoteHost()的區(qū)別小結(jié),需要的朋友可以參考下。2009-12-12基于EJB技術(shù)的商務(wù)預(yù)訂系統(tǒng)的開(kāi)發(fā)
基于EJB技術(shù)的商務(wù)預(yù)訂系統(tǒng)的開(kāi)發(fā)...2006-10-10response.setContentType()的作用及MIME參數(shù)詳解
response.setContentType(MIME)的作用是使客戶端瀏覽器,區(qū)分不同種類的數(shù)據(jù),并根據(jù)不同的MIME調(diào)用瀏覽器內(nèi)不同的程序嵌入模塊來(lái)處理相應(yīng)的數(shù)據(jù),本文詳細(xì)介紹,需要了解的朋友可以參考下2012-12-12