aspose file tools*
The moose likes JSP and the fly likes Session/Bean / jsp:getProperty problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Session/Bean / jsp:getProperty problem" Watch "Session/Bean / jsp:getProperty problem" New topic
Author

Session/Bean / jsp:getProperty problem

Zein Nunna
Ranch Hand

Joined: Mar 31, 2005
Posts: 245
Hi guys,

I have a small problem that I cant seem to get to the bottom of.

I have a bean, which has a boolean value and the relevant set/get methods.

when I use

This returns true, however further down in the code if I use scriplets as:

This returns null, Why??

The bean is session wide and I set the value in a servlet before I pass to this JSP.

What do I need to check? Have I appraoched this correctly? Your thoughts will be much appreciated.

Regards
Zein
Naseem Khan
Ranch Hand

Joined: Apr 25, 2005
Posts: 809
This returns null, Why??

The bean is session wide and I set the value in a servlet before I pass to this JSP.


As you said bean is session wide. It means bean is stored in session.

But your are retrieving a property of the bean by getAttribute(). Definitely this will give you null.

Naseem
[ August 28, 2006: Message edited by: Naseem Khan ]

Asking Smart Questions FAQ - How To Put Your Code In Code Tags
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

I'm a bit confused about the boolean thing and then getting a String attribute...
Anyway, can you show us how you set uname in the session ?


[My Blog]
All roads lead to JavaRanch
Joy Mookerji
Ranch Hand

Joined: Jul 26, 2006
Posts: 49
Why are using session,getAttribute()......
You have set the bean User into the session I guess from your servlet
as
<jsp:getProperty name="User" property="uname" />
is working properly.

Then in the scriplet

use
String user = User.getUname()
Make uname as String I didnt understand why its boolean......
Did you also use

<jsp:useBean id="User" scope="session" class="yourpackage.User" />


SCJP 5<br />Brainbench Certified in C++<br />PMP<br />Dallas,TX
Zein Nunna
Ranch Hand

Joined: Mar 31, 2005
Posts: 245
Hi guys,

Thanks for your repsponses, I've got to the bottom of the problem.

Satou/Joy - the boolean was something else I was doing at the same time and confusing its String all the way!

Naseem - I think your explanation put it all into context.

The above line of code is wrong, as session.getAttribute always returns a bean - getAttribute implies its an attribute of an object, it isnt, its a BEAN!!!

So once I had that worked out I did something to the effect


Now uname is not null and returns the right value.

Thankyou very much for your replies,
Regrad
Zein
Zein Nunna
Ranch Hand

Joined: Mar 31, 2005
Posts: 245
Actually there a mistake in the code I posted above, [rather that cut and paste I just wrote it again ]

It should generically read something like this



Regards
Zein
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

session.getAttribute always returns a bean

No, it actually returns what you've put into the session If you've put a bean, you'll get it back with getAttribute. Same if you've put an Integer, a Boolean or any objects.
Zein Nunna
Ranch Hand

Joined: Mar 31, 2005
Posts: 245
Satou,

I didnt know that, but thanks, that will be of great benefit.

Regards
Zein
Joy Mookerji
Ranch Hand

Joined: Jul 26, 2006
Posts: 49
Yes Zien "you have learned it the heard way" and I bet you wont forget it for a long time.
enjoy .............
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Session/Bean / jsp:getProperty problem