当前位置: 移动技术网 > IT编程>开发语言>Java > JSP forward用法分析实例代码分析

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

2017年12月12日  | 移动技术网IT编程  | 我要评论
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>

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网