Ho fatto questa semplice pagina jsp di test.
codice:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<%@ page pageEncoding="iso-8859-1" %>
<%
Cookie c = new Cookie ("testcookie", "dummy");
response.addCookie (c);
if (request.getParameter ("result") == null)
response.sendRedirect (request.getRequestURI () + "?result");
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Test Cookies</title>
<style type="text/css">
<!--
.ok { color: darkgreen; }
.ko { color: red; }
-->
</style>
</head>
<body>
<h1>Test Cookies</h1>
<%
if (request.getParameter ("result") != null)
{
String msg = "<span class=\"ko\">I cookie non sono accettati</span>";
Cookie[] cookies = request.getCookies ();
if (cookies != null)
{
for (Cookie cookie : cookies)
{
if (cookie.getName ().equals ("testcookie"))
{
msg = "<span class=\"ok\">I cookie sono accettati</span>";
break;
}
}
}
out.println ("<h3>" + msg + "</h3>");
}
%>
Avvia il test</p>
</body>
</html>