Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Web
Expertise: Intermediate
Nov 17, 2001

Cookies Stored by Servlets Can Be Accessible to CGI scripts or ASP Pages


By default, cookies are accessible to every HTTP request for the current directory, and any subdirectories. On most Web servers and servlet engines, servlets are located in a special directory. For example, when using a servlet runner (which ships with the Java Servlet Development Kit), servlets must be invoked under the /servlet/ directory:

http://webserver/servlet/servletname

If you want your cookies to be accessible elsewhere, you must specify the root path of your Webserver, using the avax.servlet.Cookie.setPath( String ) method.
 
// Create a cookie for everyone to share
Cookie myCookie = new Cookie ("counter", "1");

// Set path for cookie
myCookie.setPath( "/" );

Once you've set the path, any script (for example, stored in /cgi-bin/) can access the cookies stored by your servlets.
Sandeep Gain
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date