Wrox Home  
Search P2P Archive for: Go

  Return to Index  

servlets thread: cookies & servlets


Message #1 by <oca@m...> on Wed, 10 Jan 2001 11:11:05 GMT
oca@m... wrote:
> 
> I have this little problem. How do I read values from a cookie in a servlet
> that holds more then one value.
> 
> Example:
> 
>  cookie1 has this value 
> username%233Dibrene%2326userid%233D313061%2326usertype%233DT%2326
> 
> I have been looking through the servlet api and java api. But I have not found
> a metode that I can use. Do I have to do it the hard way or can one of you
> help??

If you are receiving the cookie from the client, then you can use the
servlet API. Here is an example showing how to get cookies from the
request: http://pages.about.com/kmukhar/appletServlet/GetCookies.html

If you are creating cookies in the servlet, then again, use the servlet
API.

Cookie cookie = new Cookie(name, value);
response.addCookie(cookie);

If you need multiple cookies, use an array or some other collection. You
should try to avoid treating cookies as a single string of delimited
name value-pairs. Cookies are structured data (namely name-value pairs,
with attributes), and you should try to treat a cookie as an object.
That way you can use the APIs to easily manipulate them.

K Mukhar

--- 
NEED TECHNICAL TIPS, TOOLS, AND INSIGHTS?  Is FREE okay?
Visit EarthWeb for the latest in IT Management, Software Development, 
Web Development, Networking & Communications, and Hardware & Systems.  
Click on http://www.earthweb.com for FREE articles, tutorials,
and discussions from the experts.
---
You are currently subscribed to servlets as: $subst('Recip.EmailAddr')
To unsubscribe send a blank email to leave-servlets-$subst('Recip.MemberIDChar')@p2p.wrox.com

  Return to Index