RE: Setting Cookies

2001-02-09 Thread Mikael Eriksson

Hi,

I'm not to sure about this, but the explanation below sounded some-what
logic.

Since the cookie is stored on the client machine, it can not be saved until
the browser has received a response. When you're making a forward this will
be done on the server-side only. This way the cookie will not be sent to the
page you are making the forward to. However, when that page has been sent to
the browser I guess that the cookie will be sent in all requests following
that.

/Mikael Eriksson

 -Original Message-
 From: S.Badrinarayanan [mailto:[EMAIL PROTECTED]]
 Sent: den 9 februari 2001 12:48
 To: Orion-Interest
 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.MES
 SAGE_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






Re: Setting Cookies

2001-02-09 Thread Geoff Marshall

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 +
 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