• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to disable cookies

 
Anirban Das
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I have written the following code.
//Import Servlet packages
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
public class SessionLifeCycleServlet extends HttpServlet {
protected void doGet(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException {
String action = req.getParameter("action");
if(action!=null && action.equals("invalidate")) {
HttpSession session = req.getSession();
session.invalidate();
res.setContentType("text/html");
PrintWriter out = res.getWriter();
out.println("<HTML>");
out.println("<HEAD><TITLE>Session Lifecycle</TITLE></HEAD>");
out.println("<BODY>");
out.println("<P>Your Session has been invalidated.</p>");

String lifeCycleURL = "/session/servlet/lifeCycle";
out.print("<A HREF=\""+lifeCycleURL+"?action=newSession\">");
out.println("Create new Session</A>");
out.println("</BODY></HTML>");
}
else {
HttpSession session = req.getSession(true);
res.setContentType("text/html");
PrintWriter out = res.getWriter();

out.println("<HTML>");
out.println("<HEAD><TITLE>Session Lifecycle</TITLE></HEAD>");
out.println("<META HTTP-EQUIV=\"Pragma\" CONTENT=\"no cache\">");
out.println("<BODY>");
out.println("<H! Session LifeCycle</CENTER></H1>");
out.print("<BR> Session Status - ");
if (session.isNew()) {
out.println("New Session.");
} else {
out.println("Old Session.");
}
out.print("<BR> Session Id - ");
out.println(session.getId());
out.print("<BR> Creation Time - ");
out.println(new Date(session.getCreationTime()));
out.print("<BR> Last Accessed Time - ");
out.println(new Date(session.getLastAccessedTime()));
out.print("<BR> Maximun Inactive Interval (seconds) - ");
out.println(session.getMaxInactiveInterval());

String lifeCycleURL = "/session/servlet/lifeCycle";
out.print("<BR><BR><BR><BR><A HREF=\""+lifeCycleURL+"?action=invalidate\">");
out.println("Invalidate the session</A>");
out.print("<BR><A HREF=\""+lifeCycleURL+"\">");
out.println("Reload this page</A>");
out.println("</BODY></HTML>");
out.close();
}
}
}
Although I have disabled cookies in my browser still on clicking on the "Reload link it gives me "Old Session".
Can any1 help me out telling me how to disable cookies in a Windows Xp OS with I.E 6.0.
Thanks
 
P. Udaya Shankar
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
try ur code using NS browser.
i think u have disabled cookies in browser it seems,
disable the cookie in ur page, using javascript then try it.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Cool Bamby"-
Welcome to the JavaRanch! Please adjust your displayed name to meet the
JavaRanch Naming Policy.
You can change it
here.
Thanks! and welcome to the JavaRanch!
Mark
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic