|
Problem |
The use of non-ASCII characters in HTTP Cookies, or any
other HTTP header, is not permitted. However, there are other ways to
address the issue. |
|
Solution |
According to RFC 2109 and 2068, only ASCII characters
having values from 32 to 127 are permitted within HTTP headers; which
includes HTTP Cookies. Therefore placing DBCS and other non-ASCII
characters inside of cookies is not permitted. However, there is a
programmatic solution to this problem: Encoding. The following is an
example of how this may be accomplished.
public void handleDBCSCharacters (String header,
String value,
HttpServletResponse
response){
byte b[];
try {
b =
value.getBytes(response.getCharacterEncoding());
} catch (Exception ex) {
b = value.getBytes();
}
char c[] = new char[b.length];
for (int i=0;i<b.length;i++)
c[i]=(char)(((char)b[i])&0xff);
response.setHeader(header,new String(c));
}
Please note that this code is NOT supported by WebSphere, or IBM. It is
placed here only as an example of how such encoding might be accomplished,
and to provide ideas for your own program development. |
|
|
|
|
|
|