JSP forward用法分析實例代碼分析
更新時間:2009年10月04日 15:40:50 作者:
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>
略
2.判斷時間forward到不同頁面:
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)文章
JBuilder2005實戰(zhàn)JSP之登錄頁面實現(xiàn)代碼[圖]
JBuilder2005實戰(zhàn)JSP之登錄頁面實現(xiàn)方法, 需要的朋友可以參考下2012-08-08
ajax+json+Struts2實現(xiàn)list傳遞實例講解
應(yīng)付學(xué)習(xí)需要,需要通過ajax來獲取后臺的List集合里面的值,特做了一個實例并附上演示效果,希望本例對你有所幫助2013-04-04
JDBC連接Access數(shù)據(jù)庫的幾種方式介紹
前幾天老師讓作幾個JSP連接數(shù)據(jù)庫的例子,而且連接的數(shù)據(jù)庫是Access數(shù)據(jù)庫,對于這個數(shù)據(jù)庫自己也不是太了解,后來了解到學(xué)習(xí)JDBC的時候,連接access是很方便的,很容易的,但是在連接的時候也出現(xiàn)了問題,但是還是解決了2013-05-05
jsp 判斷l(xiāng)ist是否包含string的實現(xiàn)方法
下面小編就為大家?guī)硪黄猨sp 判斷l(xiāng)ist是否包含string的實現(xiàn)方法。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2016-10-10

