mali_djuro
asked on
session.isNew returns always false?
Hi, all
i work in WSAD 5.
i need to check is session new or not. because i keep data in it. and if it is new i need to fill it with data. in other case i get data from session.
i tried
if (session.isNew()){
System.out.println("new session");
...
}
else{
System.out.println("not new session");
...
}
but it always output is
not new session
then i tried just to check does this method works fine with
session.invalidate();
session = req.getSession(true);
if (session.isNew()){
System.out.println("new session");
...
}
else{
System.out.println("not new session");
...
}
again is same output
after all i tried with this:
while(!session.isNew()){
session.invalidate();
session = req.getSession(true);
}
and i got infintive loop.
all these examples works properly in VisaulAge for Java 4,
but not in WSAD 5 .
do you have any idea where is a catch, and why it deosn't work?
thanks in advance
i work in WSAD 5.
i need to check is session new or not. because i keep data in it. and if it is new i need to fill it with data. in other case i get data from session.
i tried
if (session.isNew()){
System.out.println("new session");
...
}
else{
System.out.println("not new session");
...
}
but it always output is
not new session
then i tried just to check does this method works fine with
session.invalidate();
session = req.getSession(true);
if (session.isNew()){
System.out.println("new session");
...
}
else{
System.out.println("not new session");
...
}
again is same output
after all i tried with this:
while(!session.isNew()){
session.invalidate();
session = req.getSession(true);
}
and i got infintive loop.
all these examples works properly in VisaulAge for Java 4,
but not in WSAD 5 .
do you have any idea where is a catch, and why it deosn't work?
thanks in advance
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
hehehe... girionis, you're quick today! ;-)
Gah! And 45K ahead!
;-)
Gah! And 45K ahead!
;-)
>hehehe... girionis, you're quick today! ;-)
>
>Gah! And 45K ahead!
Hehe, that's because I do not have work and I am online all day :)
>
>Gah! And 45K ahead!
Hehe, that's because I do not have work and I am online all day :)
> Hehe, that's because I do not have work and I am online all day :)
Curse my job!! ;-) Can't wait for you to be busy again ;-)
Curse my job!! ;-) Can't wait for you to be busy again ;-)
Hehe, we take turns it seems :)
ASKER
i tried, but still is same situation. it return false.
Have you tried using the "flag" option I suggested?
It sounds like the WSAD 5 implementation of "isNew" is very loose (to the already vague specification)
It sounds like the WSAD 5 implementation of "isNew" is very loose (to the already vague specification)
>> session = req.getSession(true);
Try: session = req.getSession ( false ) != null ? req.getSession ( false ) : req.getSession ( true ) ;
Try: session = req.getSession ( false ) != null ? req.getSession ( false ) : req.getSession ( true ) ;
req.getSession ( true ) always creates a new session.
> req.getSession ( true ) always creates a new session.
I thought it created a new session if one didn't exist already?
If one already exists, it behaves the same as getSession( false ) ;
I thought it created a new session if one didn't exist already?
If one already exists, it behaves the same as getSession( false ) ;
Yes that's what it's doing. It creates a new session only if an old one does not exist.
getSession(boolean create)
Returns the current HttpSession associated with this request or, if if there is no current session and create is true, returns a new session.
getSession(boolean create)
Returns the current HttpSession associated with this request or, if if there is no current session and create is true, returns a new session.
ASKER
thanks
i need to do it very quick, so this way with attribute is fine for me right now.
when i would make some corrections in future i will consider about other options.
thanks a lot!!!
i need to do it very quick, so this way with attribute is fine for me right now.
when i would make some corrections in future i will consider about other options.
thanks a lot!!!
>> I thought it created a new session if one didn't exist already?
Yeah, you're right there. I got confused for a minute, myself :)
Yeah, you're right there. I got confused for a minute, myself :)
session = null;
session = req.getSession(true);
if (session.isNew()){
System.out.println("new session");
...
}
else{
System.out.println("not new session");
...
}