Here's my code. Seems to work...
import javax.servlet.*;
import javax.servlet.http.*;
public class SessionBean {
private boolean loggedOn;
public SessionBean() {
this.loggedOn = false;
}
// get customer ID from cookie
public String getCustId(HttpServletRequest req) {
Cookie[] cookies = req.getCookies();
if (cookies != null && cookies.length > 0) {
for (int i = 0; i < cookies.length; i++) {
Cookie cookie = cookies[i];
if ("cust_id".equals(cookie.getName())) {
String s = cookie.getValue();
s = s==null ? "" : s; // do not return null
return s;
}
}
}
return "";
}
// put customer ID into cookie and log on
public void setCustId(HttpServletResponse res, String cust) {
Cookie cookie = new Cookie("cust_id", cust);
res.addCookie(cookie);
logOn();
}
public void logOn() {
this.loggedOn=true;
}
public void logOff() {
this.loggedOn=false;
}
public boolean isLoggedOn() {
return this.loggedOn;
}
}
--
-Geoff Marshall, Director of Development
.......................................................
t e r r a s c o p e (415) 951-4944
54 Mint Street, Suite 110 direct (415) 625-0349
San Francisco, CA 94103 fax (415) 625-0306
.......................................................
> From: "S.Badrinarayanan" <[EMAIL PROTECTED]>
> Reply-To: Orion-Interest <[EMAIL PROTECTED]>
> Date: 9 Feb 2001 07:27:19 +0000
> To: Orion-Interest <[EMAIL PROTECTED]>
> Subject: Setting Cookies
>
> Hi
>
> Is there a known problem with adding cookies using orion 1.4.5? I have the
> following code to set cookies
>
> res.addCookie(new javax.servlet.http.Cookie("1", "one"));
> javax.servlet.RequestDispatcher dis =
> getServletContext().getRequestDispatcher(common.util.Utils.MESSAGE_PAGE);
> dis.forward(req, res);
>
> I am printing out the cookie values in the jsp (forward statement). But I get
> an empty list.
>
> What am I missing here?
>
> Regards
> sb
>
>
> Chequemail.com - a free web based e-mail service that also pays!!!
> http://www.chequemail.com
>
>