tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Hunter Hillegas <hhille...@jacobstern.com>
Subject RE: Retrieving Objects from the Session Results in a Null Pointer
Date Tue, 15 Aug 2000 20:48:01 GMT
Interestingly enough, if I query the session with
session.getAttributeNames(), it returns other stuff in the session but not
the shopping cart object I inserted...

But if I do the enumeration on the page that puts it into the session, it
shows up as one of the attributes.... ARGHHH!!!

So page A inserts into the session and we can determine that it is in fact
part of the session.
Page B can't find that element in the session but it can find other stuff in
the session.
Page A and B are reporting the same session Id...

How is this possible???

Hunter Hillegas, MCP
Web Engineer / System Administrator - Jacob Stern & Sons, Inc.
hhillegas@jacobstern.com
805-565-1411 PH * 805-565-8684 FAX

 -----Original Message-----
From: 	Steve Weiss [mailto:sweiss@aamc.org] 
Sent:	Tuesday, August 15, 2000 1:21 PM
To:	tomcat-user@jakarta.apache.org
Subject:	Re: Retrieving Objects from the Session Results in a Null
Pointer

Try replacing putValue(String, Object) with setAttribute(String, Object)

Also try printing out the value from session.getId() in both JSPs to see
if it's the same.

Hunter Hillegas wrote:
> 
> Sure...
> 
> Here is the code from index.jsp that creates and stores the cart:
> 
> shoppingCart cart = new shoppingCart();
> cartItem item = new cartItem("1", "family", "description", "uom", "spec",
> "sellprice", "1");
> cart.addItem(item);
> session.putValue("shoppingCart", cart);
> 
> Here is the code from another page that also is page session=true that
tries
> to read the cart...
> 
> shoppingCart cart = null;
> cart = (shoppingCart)session.getAttribute("shoppingCart"); //This is
causing
> a null pointer exception. Arghhhh...
> 
> Any ideas?
> 
> Hunter Hillegas, MCP
> Web Engineer / System Administrator - Jacob Stern & Sons, Inc.
> hhillegas@jacobstern.com
> 805-565-1411 PH * 805-565-8684 FAX
> 
>  -----Original Message-----
> From:   Steve Weiss [mailto:sweiss@aamc.org]
> Sent:   Tuesday, August 15, 2000 12:07 PM
> To:     tomcat-user@jakarta.apache.org
> Subject:        Re: Retrieving Objects from the Session Results in a Null
> Pointer
> 
> Can you post some of your code?
> 
> Hunter Hillegas wrote:
> >
> > After converting my code to use implicit sessions, I still get the same
> null
> > pointer. Any other ideas?
> >
> > Hunter Hillegas, MCP
> > Web Engineer / System Administrator - Jacob Stern & Sons, Inc.
> > hhillegas@jacobstern.com
> > 805-565-1411 PH * 805-565-8684 FAX
> >
> >  -----Original Message-----
> > From:   Steve Weiss [mailto:sweiss@aamc.org]
> > Sent:   Tuesday, August 15, 2000 11:02 AM
> > To:     tomcat-user@jakarta.apache.org
> > Subject:        Re: Retrieving Objects from the Session Results in a
Null
> > Pointer
> >
> > Using the "page session" directive is not only better, it's required to
> > maintain session information between JSPs. When you do
> > request.getSession(true/false) inside your JSP, the session object you
> > get is only valid for that page, unless you declare that the JSP is
> > "playing sessions" with other JSPs. Once you've done that, you *still*
> > need to obtain a session object with request.getSession(), and the
> > boolean parameter says "create/don't create a new one" if one doesn't
> > already exist.
> >
> > -S
> >
> > Hunter Hillegas wrote:
> > >
> > > I am sorta new to JSP. I've been doing servlets for quite some time...
> > >
> > > I understand that there is a facility to automagically use a session
on
> a
> > > page without declaring it:
> > >
> > > <%@ page session="true" %>
> > >
> > > instead of doing:
> > >
> > > theSession = request.getSession(Boolean);
> > >
> > > is declaring in the page a better approach?
> > >
> > > As far as using the depreciated method, thanks for the heads up. I'll
> try
> > > that...
> > >
> > > Hunter Hillegas, MCP
> > > Web Engineer / System Administrator - Jacob Stern & Sons, Inc.
> > > hhillegas@jacobstern.com
> > > 805-565-1411 PH * 805-565-8684 FAX
> > >
> > >  -----Original Message-----
> > > From:   Steve Weiss [mailto:sweiss@aamc.org]
> > > Sent:   Tuesday, August 15, 2000 9:56 AM
> > > To:     tomcat-user@jakarta.apache.org
> > > Subject:        Re: Retrieving Objects from the Session Results in a
> Null
> > > Pointer
> > >
> > > Two suggestions:
> > >
> > > 1. You do have- <%@ page session="true" %> in your JSPs, yes? If not
you
> > > won't be able to maintain session information from one page to
another.
> > > 2. Use session.getAttribute() instead of session.getValue(), which is
> > > deprecated.
> > >
> > > -Steve
> > >
> > > Hunter Hillegas wrote:
> > > >
> > > > I have this code:
> > > >
> > > > <%
> > > > theSession = request.getSession(false);
> > > >
> > > > shoppingCart cart = null;
> > > >
> > > > try {
> > > >     cart = (shoppingCart)theSession.getValue("shoppingCart"); //This
> is
> > > > causing a null pointer exception. Arghhhh...
> > > > }
> > > > catch (Exception e) {
> > > >     e.printStackTrace();
> > > > }
> > > > %>
> > > >
> > > > that pulls an object out of the session...
> > > >
> > > > I can verify that the object is in the session. I can grab it from
the
> > > page
> > > > I inserted it from with this code:
> > > >
> > > > shoppingCart testCart =
> > (shoppingCart)theSession.getValue("shoppingCart");
> > > >
> > > > I just can't get it from any other pages...
> > > >
> > > > Any ideas?
> > > >
> > > > Hunter Hillegas, MCP
> > > > Web Engineer / System Administrator - Jacob Stern & Sons, Inc.
> > > > hhillegas@jacobstern.com
> > > > 805-565-1411 PH * 805-565-8684 FAX
> > >
> > > --
> > > Steve Weiss      Association of American Medical Colleges
> > > (202)828-0428    mailto:sweiss@aamc.org    http://www.aamc.org
> >
> > --
> > Steve Weiss      Association of American Medical Colleges
> > (202)828-0428    mailto:sweiss@aamc.org    http://www.aamc.org
> 
> --
> Steve Weiss      Association of American Medical Colleges
> (202)828-0428    mailto:sweiss@aamc.org    http://www.aamc.org

-- 
Steve Weiss      Association of American Medical Colleges
(202)828-0428    mailto:sweiss@aamc.org    http://www.aamc.org

Mime
View raw message