my dog learned polymorphism*
The moose likes Servlets and the fly likes How to disable cookies Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to disable cookies" Watch "How to disable cookies" New topic
Author

How to disable cookies

Anirban Das
Ranch Hand

Joined: Nov 22, 2003
Posts: 63
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

Joined: Nov 18, 2003
Posts: 21
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

Joined: Feb 05, 2001
Posts: 17249
    
    6

"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


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to disable cookies
 
Similar Threads
Servlet User Roles
Session management ambiguity
Session Tracker
Problem with session.invalidate()
problem with setContentType() method