Solved

How delete a cookie in java struts application

Posted on 2010-09-04
4
967 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I had a project requirement for a displaying a user workbench .This workbench would consist multiple data grids .In each grid the user will be able to see a large number of data. These data grids should allow the user to 1. Sort 2. Export the …
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 learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

733 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