Results 1 to 8 of 8
  1. #1
    sunithamm is offline Member
    Join Date
    Dec 2009
    Posts
    19
    Rep Power
    0

    Default logout in struts2

    Hi all,
    i want to create an application which has login and logout. On successful login, user will be able to see his/her homepage. Once he clicked logout, session would be cleared and the user will go to another page from where he/she can log in again. When the browser back button is pressed after logout, user is able to see his/her homepage. Which i do not want. I want to redirect the user to login page, when browser back button is clicked after logout.

    Can anybody help me to solve this?

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,015
    Rep Power
    20

    Default Re: logout in struts2

    Prevent cacheing on the client.
    You should be able to Google for that.
    The back button isn't taking the browser to the homepage, but a cache of the homepage.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    sunithamm is offline Member
    Join Date
    Dec 2009
    Posts
    19
    Rep Power
    0

    Default Re: logout in struts2

    Hi
    Thanks for your reply.
    I wrote an interceptor as shown below:
    public class ClearCacheInterceptor extends AbstractInterceptor {

    @Override
    public String intercept(ActionInvocation invocation) throws Exception {
    ActionContext context = (ActionContext) invocation
    .getInvocationContext();
    HttpServletResponse response = (HttpServletResponse) context
    .get(StrutsStatics.HTTP_RESPONSE);

    response.setHeader("Pragma", "no-cache");


    response.setHeader("Cache-Control", "no-cache, no-store");
    response.setDateHeader("Expires", 0);
    response.setHeader("Vary", "*");

    String result = invocation.invoke();

    System.out.println("check result=" + result);

    return result;
    }

    }

    struts.xml

    <?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd">
    <struts>

    <constant name="struts.enable.DynamicMethodInvocation" value="false" />
    <constant name="struts.devMode" value="false" />
    <constant name="struts.ui.theme" value="css_xhtml" />

    <package name="action" extends="struts-default">
    <interceptors>
    <interceptor name="clear-cache" class="com.action.ClearCacheInterceptor"></interceptor>
    </interceptors>
    <action name="loginAction" class="com.action.ActionClass"
    method="login">

    <result name="success">/success.jsp</result>
    <result name="error">/login.jsp</result>
    </action>
    <action name="logoutAction" class="com.action.ActionClass"
    method="logout">
    <interceptor-ref name="clear-cache"></interceptor-ref>
    <result name="success">/logoutcomplete.jsp</result>
    </action>
    <action name="loginAgainAction" class="com.action.ActionClass"
    method="loginAgain">
    <result name="success">/login.jsp</result>
    </action>
    </package>
    </struts>


    Is this enough?
    But i am not getting the expected behaviour

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,015
    Rep Power
    20

    Default Re: logout in struts2

    WHen the back button is being used does the client make a call to the server?
    If so then you need to beef up the security on your server.
    If not then there is still something in the cache.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  5. #5
    sunithamm is offline Member
    Join Date
    Dec 2009
    Posts
    19
    Rep Power
    0

    Default Re: logout in struts2

    when browser back button is pressed, then client doesn't make call to server.

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,015
    Rep Power
    20

    Default Re: logout in struts2

    OK, then it must be cached.
    Which implies the above is not sufficient.
    Have you checked the interceptor is run?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  7. #7
    sunithamm is offline Member
    Join Date
    Dec 2009
    Posts
    19
    Rep Power
    0

    Default Re: logout in struts2

    Hi..
    sorry for the delayed reply...
    I checked and the interceptor is running.

  8. #8
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,015
    Rep Power
    20

    Default Re: logout in struts2

    Then possibly the browser is overriding it (which it is perfectly entitled to do, no-cache is only a request to the browser, not an order).
    This has hit the point where you'll simply have to trace what's going on, look at the html, monitor the cache, go through all your browser options, try it on different browsers...not really something we can handle here as it's grunt work.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Replies: 0
    Last Post: 10-30-2011, 03:38 PM
  2. logout
    By mehak in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 07-07-2011, 09:40 AM
  3. Help for logout and cookie
    By Sweety13 in forum Java Servlet
    Replies: 2
    Last Post: 01-12-2011, 06:59 AM
  4. Logout problem
    By anki1234 in forum JavaServer Pages (JSP) and JSTL
    Replies: 4
    Last Post: 01-09-2008, 07:54 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •