Stephane Grialet wrote:
> hello,
>
>
>
> i'm having problems into various portlets and screens i have written,
> using the following code line to get the uid of the connected user:
>
>
>
> String username = (String) rundata.getSession().getAttribute("username");
>
>
>
> It works almost always... but sometimes it returns "null" instead of the
> uid, and after a good number of tests i didn't succeed finding
> neither why nor under which circumstances it happened.
>
> Can someone help me ?
>
>
>
> To be sure the user session variables were set right after the
> connection, i had a few weeks ago added in the "JLoginUser.java" program
> the following code:
>
>
>
> <
>
> username = data.getParameters().getString("username","");
>
> password = data.getParameters().getString("password","");
> data.getSession().setAttribute("username",(Object) username);
>
> data.getSession().setAttribute("password",(Object) password);
> >
>
>
>
> And until my latest developed portlet and screens, it seemed to work OK
> on my Java programs.
>
> Was i right to set these session variables that way and at this place ?
>
> Are there other places i should set them to be sure that then, from any
> part of the application (portlet, screen, action,...), and at any
> time, i will be able to get these session variables values using the
> rundata.getSession().getAttribute() method.
>
> Or am i using a wrong method ?
>
It should work. Sessions are tracked using either cookies or
URL-rewriting ( the ;jsessionid=blahblah is just this ). Also, I think
sessions are host-specific, so if you have some links like
"localhost/..." and others like "127.0.0.1/..." you will get TWO
sessions, one for each prefix.
If the browser has cookies enabled, they are used. If not, the url
rewriting method is used. BUT, for every internal link, you should call
the encodeURL() or encodeRedirectURL() methods on HttpServletResponse to
ensure that every url is rewritten.
The reasons of losing sessions could be:
- session timeout due to lack of activity (I think we have 30 minutes
default)
- using different hostnames for different pages
- forgetting to call the encodeURL() stuff and the user does not accept
cookies
As far as I know, Jetspeed is doing this correctly. But your portlets
could be missing something.
Know that you know the basic mechanism, you can try to track which of
the reasons is making you lose sessions.
Also, if you use rundata.getUser().setPerm( Object), and the Object is
serializable, it should be stored in the database when the user session
expires. This is useful for permanent information about the user.
rundata.getUser()setTemp( Object) will essentially store objects in the
session, in a similar way as what you are currently doing.
>
>
> thanks,
>
> St�phane
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]