-
Notifications
You must be signed in to change notification settings - Fork 0
/
servlet.java
44 lines (33 loc) · 1017 Bytes
/
servlet.java
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
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
public class CookieServlet extends HttpServlet {
public void doGet(HttpServletRequest request,HttpServletResponse response) throws IOException {
PrintWriter out = response.getWriter();
Cookie[] c = request.getCookies();
String user = null;
String responseString = null;
if ( c != null )
{
for ( int x = 0; x < c.length; x++ )
{ String name = c[x].getName();
if ( name.equals("session_id") )
{
if((c[x].getValue()).equals("561"))
{ user = new String("ANUCE");
break;
}
}
}
}
if ( user == null )
{ response.addCookie(new Cookie("session_id", "561"));
responseString = new String("Welcome to our site,we have created a session for you.");
}
else
{ responseString = new String("Hello : " + user); }
out.println("<html>");
out.println("<body>");
out.println(responseString);
out.println("</body></html>"); }
}