-----Original Message-----
From: Mike McElligott [mailto:[EMAIL PROTECTED]]
Sent: Monday, November 08, 1999 11:41 AM
To: 'Thomas Ivers'; [EMAIL PROTECTED]
Subject: RE: Session TrackingThat's interesting, but the session object itself is already a collection of some kind. You can add your objects directly to it, rather than storing a hash within a hash...
putValue(java.lang.String name, java.lang.Object value)
Deprecated. As of Version 2.2, this method is replaced by setAttribute(java.lang.String, java.lang.Object)Mike
-----Original Message-----
From: Thomas Ivers [mailto:[EMAIL PROTECTED]]
Sent: Monday, November 08, 1999 10:22 AM
To: [EMAIL PROTECTED]
Subject: Re: Session Tracking
I wrote this mail for some colleagues. It explains how to do what you've
asked and a little bit more...
NOTE: This code is using pre 1.0 JSP specification, but does not change
significantly with different versions.From the questions I have seen posted, a lot of you could benefit from
trying this and research why it works. I hope this helps......... (;-)Attached mail
==============After a little bit of research I have finally determined how Java objects
can be passed between JSP pages. There are three basic ways that this can
be accomplished. For the sake of giving examples all of the pseudo-code is
specific to the 'session' scope. The concept stays the same for the other
scopes, but the 'session' scope should illustrate the concept.In all the following examples I assume that I have two JSP files A.jsp and
B.jsp as well as a java.util.Hashtable Object that I will call HASH. The
scenario is:1) A.jsp is called.
2) HASH is created.
3) Several entries are put into HASH.
4) Considerations are made to keep HASH available
5) A.jsp redirects to B.jsp
6) B.jsp accesses HASH and shows the entries put into it.=============
THE FIRST WAY
=============
The first way accomplishes this task by explicitly putting/getting HASH
into/from the HttpSession object.-------
A.jsp
--------
<%@language="java" import="java.util.*, javax.servlet.http.*" %>
<%
try
{
Hashtable HASH = new Hashtable();
HASH.put("one","object_one");
HASH.put("two","object_two");
HASH.put("etc","object_etc");HttpSession session = request.getSession( true );
session.putValue("hash", HASH );response.sendRedirect( response.encodeRedirectUrl("B.jsp") );
}
catch( Exception e )
{
e.printStackTrace();
}
%>
-------
B.jsp
-------
<%@language="java" import="java.util.*, java.lang.*, javax.servlet.http.*"
%>
<%
try
{HttpSession sess = request.getSession( false );
Hashtable HASH_IN_B = (Hashtable)sess.getValue("hash");String str = HASH_IN_B.toString();
Enumeration enum = HASH_IN_B.keys();
for(;enum.hasMoreElements();)
{
String key = (String)enum.nextElement();
out.println("key = " + key + ", val = " +
(String)HASH_IN_B.get( key ) + "<BR>" );
}out.println("<BR>Done");
}
catch (Exception e)
{
e.printStackTrace();
}
%>===============
THE SECOND WAY
===============
The second way accomplishes this task by implicitly creating and putting
HASH into the HttpSession object using the <BEAN> tag, and then explicitly
retrieving it using the HttpSession Object.-------
A.jsp
--------
<%@language="java" import="java.util.*, javax.servlet.http.*" %>
<BEAN NAME="HASH" INTROSPECT="no" SCOPE="session"
TYPE="java.util.Hashtable"></BEAN>
<%
try
{
HASH.put("one","object_one");
HASH.put("two","object_two");
HASH.put("etc","object_etc");response.sendRedirect( response.encodeRedirectUrl("B.jsp") );
}
catch( Exception e )
{
e.printStackTrace();
}
%>-------
B.jsp
-------
The same as the first way.===============
THE THIRD WAY
===============
The third way accomplishes this task by implicitly creating and putting HASH
into the HttpSession object using the <BEAN> tag, and then implicitly
retrieving it using the <BEAN> tag.-------
A.jsp
--------
Is the same as the second way-------
B.jsp
-------
<%@language="java" import="java.util.*, java.lang.*, javax.servlet.http.*"
%>
<BEAN NAME="HASH" INTROSPECT="no" SCOPE="session" CREATE="no"
TYPE="java.util.Hashtable"></BEAN>
<%
try
{
Hashtable HASH_IN_B = HASH;String str = HASH_IN_B.toString();
Enumeration enum = HASH_IN_B.keys();
for(;enum.hasMoreElements();)
{
String key = (String)enum.nextElement();
out.println("key = " + key + ", val = " +
(String)HASH_IN_B.get( key ) + "<BR>" );
}out.println("<BR>Done");
}
catch (Exception e)
{
e.printStackTrace();
}
%>-----Original Message-----
From: Sallis, Dan [mailto:[EMAIL PROTECTED]]
Sent: Monday, November 08, 1999 9:28 AM
To: [EMAIL PROTECTED]
Subject: Session Tracking
Can anybody show me some JSP code for setting and recalling session
variables?Thank you
Dan Sallis
Web Developer
http://www.dishnetwork.com
Echostar Communications Corp
Littleton, Colorado
(303) 723-2822===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
JSP-INTEREST".
FAQs on JSP can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
FAQs on JSP can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
Title: RE: Session Tracking
The
HASH is just an example object. Sorry for the confusion (you were not the
only one). I could have made it Object HASH = new Object(). I used
the hashtable in this example to prove an object's properties were
changed and then the changed values are retrievable.
-Tom
Ivers
- Session Tracking Nicolas Pujol
- Re: Session Tracking Greg Dinning
- Re: Session Tracking Eric Dunstan
- Re: Session Tracking Rupesh Choubey
- Re: Session Tracking Craig R. McClanahan
- Re: Session Tracking Sandu, Sathish
- Session Tracking Sallis, Dan
- Re: Session Tracking Sachin S. Khanna
- Re: Session Tracking Thomas Ivers
- Re: Session Tracking Mike McElligott
- Session Tracking Thomas Ivers
- Session Tracking [Malcolm Burlington]
- Re: Session tracking Lenin Lopez
- Session Tracking Sabari Arasu (CTC)
- Session Tracking Kumar.K.R
- Re: Session Tracking Amjad Shahrour