Solved

How delete a cookie in java struts application

Posted on 2010-09-04
4
939 Views
Last Modified: 2013-11-24
I am using send redirect to the login page, after removing the cookie but without closing the browser I am not been able to redirect to the login page

code is attached

I am using send redirect to the login page, after removing the cookie but without closing the browser I am not been able to redirect to the login page.


This is the code:

public boolean logOutCookie(HttpServletRequest req, HttpServletResponse
res, String findCookie ){
       Cookie[] cookies = req.getCookies();
       if((cookies != null) && (cookies.length > 0)) {
               for(int i=0; i<cookies.length; i++) {
                           Cookie thisCookie = cookies[i];
                       String cookieName = thisCookie.getName();
                        if(cookieName.equals(findCookie )) {
                     //        System.out.println(cookieName + ":" +
thisCookie.getValue()+" : " +thisCookie.getDomain() + ": len :" +
cookies.length   );
                                   thisCookie.setMaxAge(0);
                                   thisCookie.setPath("/");
                               thisCookie.setDomain(".sbc.com");

                               res.addCookie(thisCookie);
                  //           System.out.println("cookie Expired");
                               return true;
                        }
                       }
       }
       return true;
   }

Open in new window

0
Comment
Question by:bradbanda
4 Comments
 
LVL 40

Accepted Solution

by:
gurvinder372 earned 500 total points
ID: 33605601
http://www.javabeat.net/tips/153-how-to-delete-a-cookie-on-server-in-a-j2ee-ap.html

see how they loop through the cookies and set it to response
0
 

Expert Comment

by:ikraammomin
ID: 33715528
Hi,

Please dont use sendRedirect method. User forward method to the login page. Sendredirect will send new request and response objects.

Thanks
0
 
LVL 26

Expert Comment

by:mrcoffee365
ID: 37136735
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now