You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Paul Kofon <pk...@hotmail.com> on 2001/07/20 19:31:12 UTC

"request.getAttribute()" problems

Hi all,

I have a Bean whose scope I would like to set to "request". I would like to 
retrieve this Bean's instance when the next page is requested.
On the first page, I have:

< jsp:useBean id="beanclass" class="BeanClass" scope="request" />

On the next page, I have:

BeanClass b = (BeanClass) request.getAttribute("beanclass");

However, when I try to use instance "b" of my Bean,  I get a 
NullPointerException. The strange thing is that the code seemed to working 
in Orion. Is there something I'm doing wrong?
Note that I can use the instance without errors when I set the scope to 
"session" and use "session.getAttribute()" instead but I don't want to do 
this as my instance should only last for a request.
I'm using Tomcat 3.2.2/Sun's JDK 1.3.1 on Win2K Pro.

Regards,

Paul




_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp


Re: "request.getAttribute()" problems

Posted by David Haraburda <da...@haraburda.com>.
When you say "next page", what do you mean?  How are you going from the first
page to the second page?  This is important because if you are doing it a
certain way (such as a response.sendRedirect) your request object won't get
passed along...

David

Paul Kofon wrote:

> Hi all,
>
> I have a Bean whose scope I would like to set to "request". I would like to
> retrieve this Bean's instance when the next page is requested.
> On the first page, I have:
>
> < jsp:useBean id="beanclass" class="BeanClass" scope="request" />
>
> On the next page, I have:
>
> BeanClass b = (BeanClass) request.getAttribute("beanclass");
>
> However, when I try to use instance "b" of my Bean,  I get a
> NullPointerException. The strange thing is that the code seemed to working
> in Orion. Is there something I'm doing wrong?
> Note that I can use the instance without errors when I set the scope to
> "session" and use "session.getAttribute()" instead but I don't want to do
> this as my instance should only last for a request.
> I'm using Tomcat 3.2.2/Sun's JDK 1.3.1 on Win2K Pro.
>
> Regards,
>
> Paul
>
> _________________________________________________________________
> Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp