JSP中Cookie的处理
2007-12-23 12:35:57 来源:WEB开发网核心提示:<Html><HEAD><TITLE>Setting and Reading Cookies</TITLE></HEAD><BODY<%Cookie[] cookies = request.getCookies();boolean foundCoo
<Html>
<HEAD>
<TITLE>Setting and Reading Cookies</TITLE>
</HEAD>
<BODY
<%
Cookie[] cookies = request.getCookies();
boolean foundCookie = false;
for(int i = 0; i < cookies.length; i++) {
Cookie c = cookies[i];
if (c.getName().equals("color")) {
out.PRintln("bgcolor = " + c.getValue());
foundCookie = true;
}
}
if (!foundCookie) {
Cookie c = new Cookie("color", "cyan");
c.setMaxAge(24*60*60);
response.addCookie(c);
}
%>
>
<H1>Setting and Reading Cookies</H1>
This page will set its background color using a cookie.
</BODY>
</HTML>
<HEAD>
<TITLE>Setting and Reading Cookies</TITLE>
</HEAD>
<BODY
<%
Cookie[] cookies = request.getCookies();
boolean foundCookie = false;
for(int i = 0; i < cookies.length; i++) {
Cookie c = cookies[i];
if (c.getName().equals("color")) {
out.PRintln("bgcolor = " + c.getValue());
foundCookie = true;
}
}
if (!foundCookie) {
Cookie c = new Cookie("color", "cyan");
c.setMaxAge(24*60*60);
response.addCookie(c);
}
%>
>
<H1>Setting and Reading Cookies</H1>
This page will set its background color using a cookie.
</BODY>
</HTML>
(出处:http://www.cncms.com)
更多精彩
赞助商链接