devxlogo

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

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 shareCookie myCookie = new Cookie ("counter", "1");// Set path for cookiemyCookie.setPath( "/" );

size=3>
Once you’ve set the path, any script (for example, stored in /cgi-bin/) can access the cookies stored by your servlets.

devx-admin

Share the Post: