Bug 33961

Summary: session cookies for context containing '~' do not work
Product: Tomcat 5 Reporter: xamul <luigi.zanderighi>
Component: CatalinaAssignee: Tomcat Developers Mailing List <dev>
Severity: normal CC: luigi.zanderighi
Priority: P2    
Version: 5.5.7   
Target Milestone: ---   
Hardware: All   
OS: All   
URL: http://www.hostingjava.it

Description xamul 2005-03-11 13:21:46 UTC
I you create an application containing '~' character cookies do non work
properly,  because the url set in the cookie encodes the ~ character in
urlencoded format.
For example if your context name is 
The cookies send back to the client are with a path:

This makes the server unable to recognize the sessionid, like cookies were disabled.
Comment 1 Remy Maucherat 2005-03-24 18:20:49 UTC
Comment 2 Steffen Spahr 2006-11-15 05:11:43 UTC

I am using Apache Tomcat/5.5.17.

With this version I got the same result as described in the bug-report.

Is it realy fixed?

The Cookie.getPath() and Cookie.getDomain() returns always 'null'.

My example program:

package test;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class CookieAnzeige extends HttpServlet {
	private static final long serialVersionUID = 1L;

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// Returns a writer to write to the browser
		PrintWriter out = response.getWriter();

		// Writes the string to the browser.
		out.println("Anzeige und Setzen von Cookies:");

		Cookie[] cookies = request.getCookies();
		if (cookies == null)
			out.println("Kein Cookie gesetzt!");
		else {
			for (int i = 0; i < cookies.length; i++) {
				String cookieName = cookies[i].getName();
				out.println("Cookie " + cookieName + " hat den Wert "
						+ cookies[i].getValue() + " Pfad: "
						+ cookies[i].getPath() + " Domain: "
						+ cookies[i].getDomain());

		Cookie Versicherungsnehmer = new Cookie("Versicherungsnehmer", "123456");


The result:

Anzeige und Setzen von Cookies:

Cookie JSESSIONID hat den Wert A08AE263E7D9854C649BEA65CDE5056A Pfad: null
Domain: null

Cookie Versicherungsnehmer hat den Wert 123456 Pfad: null Domain: null 
Comment 3 Steffen Spahr 2006-11-15 05:18:25 UTC

my mistake !!! 

The correct Bug-Report-number is ASF Bugzilla Bug 16474.