Servlet与Jsp学习笔记--4、Session

设置过期

    <session-config>

        <session-timeout>30</session-timeout>

</session-config>

 

编码方式

HttpSession session = request.getSession( );

session.setMaxInactiveInterval(20 * 60);//20分钟后过期

 

跟踪

<%@page contentType="text/html"%>

<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>

<%@ taglib uri="http://java.sun.com/jstl/fmt" prefix="fmt" %>

 

<html>

 <head><title>View Session JSP </title></head>

 <body>

 

    <h2>Session Info From A JSP</h2>

 

    The session ID: <c:out value="${pageContext.session.id}"/>

 

    <h3>Session date values formatted as Dates</h3>

 

    <jsp:useBean id="timeValues" class="java.util.Date"/>

 

    <c:set target="${timeValues}" value=

      "${pageContext.session.creationTime}" property="time"/>

 

    The creation time: <fmt:formatDate value="${timeValues}" type="both"

           dateStyle="medium" /><br><br>

 

    <c:set target="${timeValues}" value=

    "${pageContext.session.lastAccessedTime}" property="time"/>

 

    The last accessed time: <fmt:formatDate value="${timeValues}" type=

      "both" dateStyle="short" />

 

 </body>

</html>

 

 

posted @ 2009-01-16 16:02  昕友软件开发  阅读(191)  评论(0编辑  收藏  举报
欢迎访问我的开源项目:xyIM企业即时通讯