JSP New Session Parameter : Session « JSP « Java






JSP New Session Parameter


<%@ page import="java.util.*" %>
<%
  // add parameter to session
  String name = request.getParameter("name");
  String value = request.getParameter("value");
  if (name!=null && value!=null && name.length()>0) {
    session.setAttribute(name,value);
  }
  Date lastVisit = (Date)session.getAttribute("lastVisit");
  Date thisVisit = new Date();
%>
<HTML>
  <HEAD>
    <TITLE>Session List</TITLE>
  </HEAD>
  <BODY>
    <H1>Session List</H1>
    Last visit: <%= lastVisit %><BR>
    This visit: <%= thisVisit %><BR>
    Session ID: <%= session.getId() %><BR>
    Session max interval: <%= session.getMaxInactiveInterval() %><BR>

    <H2>Session parameters</H2>
    <%
      Enumeration enum = session.getAttributeNames();
      while (enum.hasMoreElements()) {
        String attribute = (String) enum.nextElement();
        out.println(""+attribute+"="+
          session.getAttribute(attribute)+"<BR>");
      }
        session.setAttribute("lastVisit",thisVisit);
    %>

    <H2>New session parameter</H2>
    <FORM>
        <P>Name: <INPUT TYPE='TEXT' NAME='name'></P>
        <P>Value: <INPUT TYPE='TEXT' NAME='value'></P>
      <INPUT TYPE='SUBMIT' VALUE='Add new value'>
    </FORM>
  </BODY>
</HTML>
           
       








JSP-New-Session-Parameter.zip( 89 k)

Related examples in the same category

1.JSP: display a session info
2.JSP Session Parameter Rewrite
3.Jsp Session Cart
4.Use Session Jsp
5.Jsp Using Bean Scope Session
6.Print the request headers and the session attributes
7.Using Sessions to Track Users
8.Sessions disabled
9.Duplicated session varaibles
10.JSP: view session
11.JSP and session
12.JSP and session 2
13.JSP session counter