-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathCookies_jsp.jsp
72 lines (58 loc) · 1.89 KB
/
Cookies_jsp.jsp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<%@ page import="java.util.*" %>
<%
Cookie[] cookies = request.getCookies();
if (cookies == null) {
cookies = new Cookie[0];
}
Date d= new Date();
Cookie c = new Cookie("Last_Visited", "" +d);
response.addCookie(c);
String name = request.getParameter("name");
String value = request.getParameter("value");
Cookie added = null;
if (name != null && value != null && name.length() > 0) {
Cookie cookie = null;
for (int i = 0; i < cookies.length; i++) {
if (cookies.length >= 10) {
cookie = cookies[0];
cookie.setMaxAge(0);
response.addCookie(cookie);
}
}
added = new Cookie(name, value);
response.addCookie(added);
}
%>
<HTML>
<HEAD>
<TITLE>Cookies</TITLE>
</HEAD>
<BODY>
<
<b>Number of cookies: <%= cookies.length%></b><BR>
<H3>Cookies</H3>
<%
for (int i = 0; i < cookies.length; i++) {
out.println("cookie number:\n" + i);
out.println( " \t cookie name:\n" + cookies[i].getName());
out.println("\t cookie value:\n" + cookies[i].getValue());
%>
<br>
<%
if (added != null && added.getName().equals(cookies[i].getName())) {
added = null;
}
}
if (added != null) {
out.println("new cookie: " + added.getName() + ":\t"
+ added.getValue() + "<BR>");
}
%>
<H2>New cookie</H2>
<FORM>
<P>Name: <INPUT TYPE='TEXT' NAME='name'></P>
<P>Value: <INPUT TYPE='TEXT' NAME='value'></P>
<INPUT TYPE='SUBMIT' VALUE='Add new value'>
</FORM>
</BODY>
</HTML>