开发学院WEB开发Jsp JSP中forward用法 阅读

JSP中forward用法

 2009-10-25 16:35:11 来源:WEB开发网   
核心提示:1.首页(填写姓名)(可选,表单post到time.jsp即可):略2.判断时间forward到不同页面:time.jsp:<%-- Document : index Created on : 2009-10-3, 15:48:00 Author : lucifer--%><%@page co

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>

Tags:JSP forward 用法

编辑录入:爽爽 [复制链接] [打 印]
[]
  • 好
  • 好的评价 如果觉得好,就请您
      0%(0)
  • 差
  • 差的评价 如果觉得差,就请您
      0%(0)
赞助商链接