You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Mark Lowe <ma...@talk21.com> on 2003/07/23 10:43:44 UTC

NullPointer exception

Before I wash anymore time out on stuff that really shouldn't happen, 
may I ask if anyone else has had problems with anything being stored in 
the request and/or session returning null..

for example imagine i've 2 actions

// in action 1

HttpSession session = request.getSession()
session.setAttribute("test","mellow");
mapping.findForward("success");

//action 2

HttpSession session = request.getSession();
//Next line returns null
String str = session.getAttribute("test").toString();
mapping.findForward("success");

I've tried the same with request rather than session, but I keep 
getting null.. Now there appears to be something setting the request to 
null between actions, I just have no idea what. This sort of thing 
really should be happening, has anyone else got this problem?

Request nor session will even let be get a string from it!!!






---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


RE: NullPointer exception

Posted by Andrew Hill <an...@gridnode.com>.
<snip>
Btw, thanks for the "best practice" tip.. When's the book comming out ;)
</snip>

Hehe, I could never hope to compete with the excellent books already out
there:

"Sruts In Action" (No the title is not a dig at how long it took to release
1.1 ;-> )
http://www.amazon.com/exec/obidos/tg/detail/-/1930110502/ref=pd_sim_books_1/
104-3048226-9331911?v=glance&s=books

"Programming Jakarta Struts"
http://www.amazon.com/exec/obidos/tg/detail/-/0596003285/104-3048226-9331911
?vi=glance

"Struts Kickstart"
http://www.bookpool.com/.x/z5tt7pe7ii/sm/0672324725 (Not on Amazon would you
believe!)

And essential reading if your new to web application programming (or even if
your not):

"Java Servlet Programming"
http://www.amazon.com/exec/obidos/tg/detail/-/156592391X/104-3048226-9331911
?vi=glance


-----Original Message-----
From: Mark Lowe [mailto:mark.lowe@talk21.com]
Sent: Wednesday, 23 July 2003 17:24
To: Struts Users Mailing List
Subject: Re: NullPointer exception


I had to use the scope attribute on the action tag in struts-config.xml

Which i thought would only be to scope the form bean, defined by the
name attribute but it would appear not.

Btw, thanks for the "best practice" tip.. When's the book comming out ;)

Cheers Mark

On Wednesday, July 23, 2003, at 09:55 AM, Andrew Hill wrote:

> <snip>
> Now there appears to be something setting the request to
> null between actions, I just have no idea what.
> </snip>
>
> Well of course the request attributes are null (i presume its the
> request
> attribute thats null and not the request reference itself!) in the
> second
> action. Unless you do a server-side redirect direct to it from the
> first
> action (which Im assuming your not - unless your doing action chaining
> (which is bad)) then you will be hitting it as a result of a *new*
> request
> from the browser.
>
> <snip>
> This sort of thing really should be happening
> </snip>
>
> Ahh... glad you recognise that ;-) but it should not be happening for
> the
> session.
>
> Im not sure why you are having problems getting it out of the session.
> It
> could be that your session tracking isnt working properly. Check that
> you
> either have cookies enabled in your browser, or if not that you are
> rewriting any urls that need it. (In the case of a forms action url
> this
> will be done automaticlly by the struts html:form tag) (- its
> considered
> best practice for your application to be able to work without cookies
> btw -
> which makes url rewriting in your pages essential.)
>
> -----Original Message-----
> From: Mark Lowe [mailto:mark.lowe@talk21.com]
> Sent: Wednesday, 23 July 2003 16:44
> To: Struts List
> Subject: NullPointer exception
>
>
> Before I wash anymore time out on stuff that really shouldn't happen,
> may I ask if anyone else has had problems with anything being stored in
> the request and/or session returning null..
>
> for example imagine i've 2 actions
>
> // in action 1
>
> HttpSession session = request.getSession()
> session.setAttribute("test","mellow");
> mapping.findForward("success");
>
> //action 2
>
> HttpSession session = request.getSession();
> //Next line returns null
> String str = session.getAttribute("test").toString();
> mapping.findForward("success");
>
> I've tried the same with request rather than session, but I keep
> getting null.. Now there appears to be something setting the request to
> null between actions, I just have no idea what. This sort of thing
> really should be happening, has anyone else got this problem?
>
> Request nor session will even let be get a string from it!!!
>
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: NullPointer exception

Posted by Mark Lowe <ma...@talk21.com>.
I had to use the scope attribute on the action tag in struts-config.xml

Which i thought would only be to scope the form bean, defined by the 
name attribute but it would appear not.

Btw, thanks for the "best practice" tip.. When's the book comming out ;)

Cheers Mark

On Wednesday, July 23, 2003, at 09:55 AM, Andrew Hill wrote:

> <snip>
> Now there appears to be something setting the request to
> null between actions, I just have no idea what.
> </snip>
>
> Well of course the request attributes are null (i presume its the 
> request
> attribute thats null and not the request reference itself!) in the 
> second
> action. Unless you do a server-side redirect direct to it from the 
> first
> action (which Im assuming your not - unless your doing action chaining
> (which is bad)) then you will be hitting it as a result of a *new* 
> request
> from the browser.
>
> <snip>
> This sort of thing really should be happening
> </snip>
>
> Ahh... glad you recognise that ;-) but it should not be happening for 
> the
> session.
>
> Im not sure why you are having problems getting it out of the session. 
> It
> could be that your session tracking isnt working properly. Check that 
> you
> either have cookies enabled in your browser, or if not that you are
> rewriting any urls that need it. (In the case of a forms action url 
> this
> will be done automaticlly by the struts html:form tag) (- its 
> considered
> best practice for your application to be able to work without cookies 
> btw -
> which makes url rewriting in your pages essential.)
>
> -----Original Message-----
> From: Mark Lowe [mailto:mark.lowe@talk21.com]
> Sent: Wednesday, 23 July 2003 16:44
> To: Struts List
> Subject: NullPointer exception
>
>
> Before I wash anymore time out on stuff that really shouldn't happen,
> may I ask if anyone else has had problems with anything being stored in
> the request and/or session returning null..
>
> for example imagine i've 2 actions
>
> // in action 1
>
> HttpSession session = request.getSession()
> session.setAttribute("test","mellow");
> mapping.findForward("success");
>
> //action 2
>
> HttpSession session = request.getSession();
> //Next line returns null
> String str = session.getAttribute("test").toString();
> mapping.findForward("success");
>
> I've tried the same with request rather than session, but I keep
> getting null.. Now there appears to be something setting the request to
> null between actions, I just have no idea what. This sort of thing
> really should be happening, has anyone else got this problem?
>
> Request nor session will even let be get a string from it!!!
>
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


RE: NullPointer exception

Posted by Andrew Hill <an...@gridnode.com>.
<snip>
Now there appears to be something setting the request to
null between actions, I just have no idea what.
</snip>

Well of course the request attributes are null (i presume its the request
attribute thats null and not the request reference itself!) in the second
action. Unless you do a server-side redirect direct to it from the first
action (which Im assuming your not - unless your doing action chaining
(which is bad)) then you will be hitting it as a result of a *new* request
from the browser.

<snip>
This sort of thing really should be happening
</snip>

Ahh... glad you recognise that ;-) but it should not be happening for the
session.

Im not sure why you are having problems getting it out of the session. It
could be that your session tracking isnt working properly. Check that you
either have cookies enabled in your browser, or if not that you are
rewriting any urls that need it. (In the case of a forms action url this
will be done automaticlly by the struts html:form tag) (- its considered
best practice for your application to be able to work without cookies btw -
which makes url rewriting in your pages essential.)

-----Original Message-----
From: Mark Lowe [mailto:mark.lowe@talk21.com]
Sent: Wednesday, 23 July 2003 16:44
To: Struts List
Subject: NullPointer exception


Before I wash anymore time out on stuff that really shouldn't happen,
may I ask if anyone else has had problems with anything being stored in
the request and/or session returning null..

for example imagine i've 2 actions

// in action 1

HttpSession session = request.getSession()
session.setAttribute("test","mellow");
mapping.findForward("success");

//action 2

HttpSession session = request.getSession();
//Next line returns null
String str = session.getAttribute("test").toString();
mapping.findForward("success");

I've tried the same with request rather than session, but I keep
getting null.. Now there appears to be something setting the request to
null between actions, I just have no idea what. This sort of thing
really should be happening, has anyone else got this problem?

Request nor session will even let be get a string from it!!!






---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org