Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How delete a cookie in java struts application

Posted on 2010-09-04
4
Medium Priority
?
996 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:
Gurvinder Pal Singh earned 2000 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

Industry Leaders: 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

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…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

618 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