ASCII码 ASCII码

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

发布于:2022-03-30 12:56:59  栏目:技术文档
  1. JSP forward用法分析实例代码分析
  1. JSP forward用法分析,需要的朋友可以参考下。
  2. 1.首页(填写姓名)(可选,表单post到time.jsp即可):
  3. 2.判断时间forward到不同页面:
  4. time.jsp:
  1. <%--
  2. Document : index
  3. Created on : 2009-10-3, 15:48:00
  4. Author : lucifer
  5. --%>
  6. <%@page contentType="text/html" pageEncoding="UTF-8"%>
  7. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  8. "http://www.w3.org/TR/html4/loose.dtd">
  9. <%@page import="java.util.Date" %>
  10. <html>
  11. <head>
  12. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  13. <title>JSP Page</title>
  14. </head>
  15. <body>
  16. <%
  17. Date dat =
  18. new Date();
  19. if(dat.getHours() <= 12){
  20. %>
  21. <jsp:forward page="AmGreeting.jsp"/>
  22. <%}
  23. else{
  24. %>
  25. <jsp:forward page="PmGreeting.jsp"/>
  26. <%}
  27. %>
  28. </body>
  29. </html>
  1. 3.如果是早上:
  2. AmGreeting.jsp:
  1. <%--
  2. Document : AmGreeting
  3. Created on : 2009-10-3, 16:00:10
  4. Author : lucifer
  5. --%>
  6. <%@page contentType="text/html" pageEncoding="UTF-8"%>
  7. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  8. "http://www.w3.org/TR/html4/loose.dtd">
  9. <html>
  10. <head>
  11. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  12. <title>JSP Page</title>
  13. </head>
  14. <body>
  15. <h1>Good Morning! </h1>
  16. <%
  17. String name = request.getParameter("userName");
  18. out.println(name);
  19. %>
  20. !!!
  21. </body>
  22. </html>
  1. 如果是下午:
  2. PmGreeting.jsp:
  1. <%--
  2. Document : AmGreeting
  3. Created on : 2009-10-3, 16:00:10
  4. Author : lucifer
  5. --%>
  6. <%@page contentType="text/html" pageEncoding="UTF-8"%>
  7. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  8. "http://www.w3.org/TR/html4/loose.dtd">
  9. <html>
  10. <head>
  11. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  12. <title>JSP Page</title>
  13. </head>
  14. <body>
  15. <h1>Good Afternoon! </h1>
  16. <%
  17. String name = request.getParameter("userName");
  18. out.println(name);
  19. %>
  20. !!!
  21. </body>
  22. </html>
相关推荐
阅读 +