Solved

How delete a cookie in java struts application

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Java array passed to SQL where clause 23 64
eclipse argument 14 53
session migration servlets 2 28
how to see all occupied ports on windows 10 laptop 15 26
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…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
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…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

863 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

26 Experts available now in Live!

Get 1:1 Help Now