Solved

How delete a cookie in java struts application

Posted on 2010-09-04
4
955 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 27

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
couple of eclipse 5 38
servlet example 11 40
throw exception 21 44
Desingning Refactoring existing code 2 24
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
The viewer will learn how to implement Singleton Design Pattern in Java.

831 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