Sto provando ad impostare il valore unicode all'interno del cookie ma non lo accetta e lancia Eccezione. Ho controllato il valore esadecimale della stringa ed è corretto ma getta Exception mentre aggiungo ad un cookie.java.lang.IllegalArgumentException: Controllo carattere nel valore del cookie o attributo
private void fnSetCookieValues(HttpServletRequest request,HttpServletResponse response)
{
Cookie[] cookies=request.getCookies();
for (int i = 0; i < cookies.length; i++) {
System.out.println(""+cookies.length+"Name"+cookies[i].getName());
if(cookies[i].getName().equals("DNString"))
{
System.out.println("Inside if:: "+cookies[i].getValue()+""+cookies.length);
try {
String strValue;
strValue = new String(request.getParameter("txtIIDN").getBytes("8859_1"),"UTF8");
System.out.println("Cookie Value To be stored"+strValue);
for (int j = 0; j < strValue.length(); j++) {
System.out.println("Code Point"+Integer.toHexString(strValue.codePointAt(j)));
}
Cookie ck = new Cookie("DNString",strValue);
response.addCookie(ck);
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
ottengo:
java.lang.IllegalArgumentException: Control character in cookie value or attribute.
quando si aggiunge il cookie per oggetto risposta. Sto usando Tomcat 7 e Java 7 come ambiente di runtime.
grazie funziona !! –
Prego. – BalusC