wood burning stoves 2.0*
The moose likes Struts and the fly likes Default not-initialized Struts2 session value Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Default not-initialized Struts2 session value" Watch "Default not-initialized Struts2 session value" New topic
Author

Default not-initialized Struts2 session value

Sam Gardner
Ranch Hand

Joined: Jul 22, 2008
Posts: 48
Hey Guys -

I'm trying to get my login/logout procedures locked down in a Struts2 app, and I've run into a bit of a snag.



edit: If I didn't make this obvious, this doesn't work. After logout, the check functions as intended, but not '#session.user == ""'.

session.user is only set at login and logout now (to the username at login, and "none" at logout). I want to catch the case where someone visits the site without having any session information yet - ie session.user hasn't been created/initialized yet. I don't want to set session.user to something whenever a user visits the site, so they can "remember" their login for a set period of time for a while. What should the check be for that?

Thanks for any help!



[ November 26, 2008: Message edited by: Sam Gardner ]
[ November 26, 2008: Message edited by: Sam Gardner ]
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Aren't you checking for an empty string? What happens if you check for null?

That said, this isn't the way I'd recommend doing something like that--this seems like it'd be something better put in an interceptor, rather than polluting all the JSP pages with the extra code.
Sam Gardner
Ranch Hand

Joined: Jul 22, 2008
Posts: 48
I've tried checking for null, and it doesn't work, at least like '#session.user != null'. Is that how you check for null values in Struts? I'm quite new at this framework, if it isn't completely obvious.

As far as interceptors go, this way first occured to me, and the if/then I have now is implemented in "templates" that I include in my JSP pages to keep all of the common code easy to manage, so the checks don't do much cluttering up of the page. Unless there's a decent performance hit, I'd rather figure this out and work on an equivalent interceptor later on.

Thanks
[ November 26, 2008: Message edited by: Sam Gardner ]
 
 
subject: Default not-initialized Struts2 session value
 
Similar Threads
Struts2
invalidate session object in struts2
Recommendations for Webhosting for Struts2 (GoDaddy issue)
Struts2-json plugin not serializing action class to json
SaveToken