File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes Problem in reading cookies Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Problem in reading cookies" Watch "Problem in reading cookies" New topic

Problem in reading cookies

amitabh pandey

Joined: Mar 16, 2012
Posts: 9
i am facing an strange problem.There are one java application with struts.
it is working fine.
there was one modification in this application that we need to change this application to read user id by cookies.
So in login action class i read the cookie and set to formbean property.
but when next time in any action it is going to read data from it is comming null.
i simply do
1-read cookie value which is userid suppose it is coming 00116084
now i set this value to userid frombean propert by form.setUserId(00116084)
now when
user call login method
i simply read userid from bean and call db method. and set value in session as it was
till here every thing is fine.
now when i read userid from session in any other class it gives error null in seesion.
so it is happning .the proble only when i read user id from cookie and set it to formbean.
please help this is urgent

vipul bondugula
Ranch Hand

Joined: Oct 14, 2010
Posts: 219
Hi pandey,

There is no need to set the userid to the fombean object and then store it in the session. you can directly store it in the session.Like,

You can do as in above. In your scenario, check the form bean scope. i mean whether it is request (or) session scope. If it is request , what happens is for every request prior to populate() , reset() is called. which clears previous values.

Vipul Kumar
amitabh pandey

Joined: Mar 16, 2012
Posts: 9
Hi vipul
thanks for reply

my first question if i set directly into the seesion as you tell then will problemget resolved means this was the problem.
or after thuis i need to check another thing as scope.

but why it reset when i comes by cookies
means when i access normaly then it is ok.

and please tellme how i resolve this problem

I agree. Here's the link:
subject: Problem in reading cookies
jQuery in Action, 3rd edition