August 3, 2009

Servlets: Cookie name is a reserved token

Topic:  Servlets 2.4

Application Server: JBoss 4.0.2 / Tomcat 5.5.9

Exception:

java.lang.IllegalArgumentException: Cookie name "ab,cd" is a reserved token
	javax.servlet.http.Cookie.<init>(Cookie.java:140)
	com.HelloWorldServlet2.doGet(HelloWorldServlet2.java:28)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:697)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
	org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:81)

Resolution:

Cookie 'names' can only consist of Alphanumeric characters and cannot contain the following: commas, semicolons, whitespace and they cannot start with the $ character.

Usage of the prohibited characters in the Cookie constructor for the first String argument which sets the name of the Cookies results in an IllegalArgumentException. Removal of the prohibited character/s removes this exception.

No comments:

Post a Comment