Hi all Servleters,
I am new to Cookies and Session Variables,
i am facing a problem using both. I have created
a logon screen i am accepting username and password
from it. when submitted i am storing username in a
cookie after validation, I am reading value of cookie
from another servlet (it works fine for first time),
but when i go to previous page I change username, the
servlet for validation gets called on submitting and
it stores the value of username into cookie, but this
time i get the old value from the cookie when i read
it from the other servlet.
I tried the same with Session Variables and I am
getting always the old value.
What can be the problem?
Please help me. if possible provide code also. (pl.
tell me do i need to change any brower setting?)
Thank you in advance
Shrikant
the code written service method which validates user
and add a cookie.
-------
-------
String ruser;
ruser = request.getParameter("uid");
out.println("value of ruser is " + ruser);
//-- The Cookie Matter goes
here-----------------------------
Cookie theCookie = null;
Cookie cookies[] = request.getCookies();
if (cookies==null){
theCookie = new Cookie ("C_USERID",ruser);
theCookie.setMaxAge (-1);
theCookie.setSecure(false);
response.addCookie(theCookie);
}
else // if cookie already exists change the
value of C_USERID cookie
{
theCookie=cookies[0];
theCookie.setMaxAge(0); // delete the
cookie
response.addCookie(theCookie);
// recreate the cookie
theCookie = new Cookie ("C_USERID",ruser);
theCookie.setMaxAge (-1);
theCookie.setSecure(false);
response.addCookie(theCookie);
}
-------
------
=================================================================
the code written in the other servlet which uses the
cookie
I am just displaying the value of cookie (code is
written in service method)
--------
--------
String ruser;
Cookie cookies[]= request.getCookies();
Cookie gotCookie = null;
if (cookies==null)
{
out.println("No Cookie is received ");
}
else
{
gotCookie = cookies[0];
ruser = gotCookie.getValue();
for (int i = 0;i < cookies.length;i++)
{
out.println(" the value of cookie received
"+gotCookie.getName() + " is " + ruser);
}
}
----------
---------
__________________________________________________
Do You Yahoo!?
Get Yahoo! Mail � Free email you can access from anywhere!
http://mail.yahoo.com/
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html