当前位置: 首页 > 图文教程 > 网络编程 > JSP > JSP forward用法分析实例代码分析

JSP
写一个对搜索引擎友好的文章SEO分页类
ajax+jsp草稿自动保存的实现代码
什么是eclipse,eclipse的意思解析
经常听朋友说什么J2EE,终于知道点什么是J2EE了,汗一个
搭建SSH时的思考和遇到的几个问题的解决方法
RMI使用学习 小结
weblogic 8.1下重新编译java类但不用重启服务器的方法
JSP下动态INCLUDE与静态INCLUDE的区别分析
jsp中文乱码 jsp mysql 乱码的解决方法
Jsp页面实现文件上传下载类代码
下载完成后页面不自动关闭的方法
XStream使用方法总结附实例代码
惊现支撑1亿pv/天的超级数据库解决方案
jsp遍历文件夹下的文件的代码
JSP中include指令和include行为的区别
FCKeditor使用方法(FCKeditor_2.6.3)详细使用说明
AJAX FCKEditor Rich Editor整合篇
Java下使用Oracle存储过程(详解)
java AJAX实现级联下拉框
java去掉html标签 必须首先去掉双引号的正则

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-10-11   浏览: 500 ::
收藏到网摘: n/a

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>