Tôi đang cố gắng đặt giá trị unicode bên trong cookie nhưng nó không chấp nhận điều này và ném Ngoại lệ. Tôi đã kiểm tra giá trị thập lục phân của chuỗi và nó là chính xác nhưng ném ngoại lệ trong khi thêm vào một cookie.java.lang.IllegalArgumentException: Kiểm soát ký tự trong giá trị cookie hoặc thuộc tính
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();
}
}
}
}
tôi nhận được:
java.lang.IllegalArgumentException: Control character in cookie value or attribute.
khi thêm các tập tin cookie để đối tượng phản ứng. Tôi đang sử dụng Tomcat 7 và Java 7 làm môi trường thời gian chạy.
nhờ nó hoạt động !! –
Bạn được chào đón. – BalusC