page属性只在一次页面中有效

时间:2022-07-04 17:09:05
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="java.text.SimpleDateFormat"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>page属性只在一次页面中有效</title>
    
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">    
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->


  </head>
  
  <body>
   <%
    pageContext.setAttribute("name","李兴华");
    pageContext.setAttribute("age", 30);
    pageContext.setAttribute("birthday", new Date());
    %>
    <%
      String username=(String)pageContext.getAttribute("name");
      Integer userage=(Integer)pageContext.getAttribute("age");
      Date userbirthday=(Date)pageContext.getAttribute("birthday");
      SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
      String dateformat=sdf.format(userbirthday);
     %>
     <h2>姓名:<%=username%></h2>
     <h2>年龄:<%=userage%></h2>
     <h2>生日:<%=dateformat%></h2>
  </body>
</html>