• JSP内置对象-----session


    <%@page import="java.sql.Date"%>
    <%@page import="java.text.SimpleDateFormat"%>
    <%@ page language="java" contentType="text/html; charset=utf-8"
        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内置对象-session</title>
    </head>
    <body>
        <h1>session常用方法</h1>
        <hr>
        <%
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");
            
            Date d = new Date(session.getCreationTime());
            
            session.setAttribute("userName", "张三");
            
            session.setAttribute("password", "123456");
            
            session.setAttribute("age", "20");
            
            //设置当前session最大生成周期单位是秒
            session.setMaxInactiveInterval(10);//10秒钟
            
            
        %>
        Session创建时间:<%=sdf.format(d)%><br> Session的ID编号:<%=session.getId()%><br>
        从session中获取用户名:<%=session.getAttribute("userName")%><br>
        <a href="neizhiSession2.jsp" target="_blank">跳转到neizhiSession2</a>
    
    
    </body>
    </html>
     
    <%@page import="java.sql.Date"%>
    <%@page import="java.text.SimpleDateFormat"%>
    <%@ page language="java" contentType="text/html; charset=utf-8"
        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内置对象-session</title>
    </head>
    <body>
        <h1>session常用方法</h1>
        <hr>
        <%
            
        %>
    
        Session的ID编号:<%=session.getId()%><br> 从session中获取用户名:<%=session.getAttribute("userName")%><br>
        Session中保存的属性有:<%
            String[] names = session.getValueNames();
            for (int i = 0; i < names.length; i++)
            {
                out.println(names[i] + "&nbsp;&nbsp;");
            }
        %><br>
    
    
    </body>
    </html>

     

  • 相关阅读:
    继承
    JAVA接口的继承与集合
    JAVA接口
    c++程序—敲桌子
    c++程序—水仙花数
    c++程序—while猜数字游戏
    c++程序—switch分支
    c++程序—三目运算符
    c++程序—if语句实践
    c++程序—选择结构
  • 原文地址:https://www.cnblogs.com/1ming/p/9447205.html
Copyright © 2020-2023  润新知