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( "/" );


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

See also  How to Create and Deploy QR Codes Online: A Comprehensive Guide
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist