JSP forward usage analysis example code analysis

  • 2020-05-24 05:58:30
  • OfStack

1. Home page (name) (optional, form post to time.jsp) :
slightly
2. Judge the time forward to different pages:
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. If it's morning:
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> 

If it's in the afternoon:
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> 

Related articles: