problem with Session expiration in Struts

Discussion in 'Java' started by vyshu, Apr 24, 2007.

  1. vyshu

    vyshu Guest

    hi,
    i have created a small aplication using struts.I just want to know how
    to give a session timeout for my application.Once the session has
    expired,the user should be redirected to the login page,whenever he
    clicks on any link or button.It would be really helpful if anyone can
    give me the code to be added to my action servlets or my struts-config
    file.
    thanks,
    vaisakh.
     
    vyshu, Apr 24, 2007
    #1
    1. Advertising

  2. vyshu

    Lew Guest

    vyshu wrote:
    > hi,
    > i have created a small aplication using struts.I just want to know how
    > to give a session timeout for my application.Once the session has
    > expired,the user should be redirected to the login page,whenever he
    > clicks on any link or button.It would be really helpful if anyone can
    > give me the code to be added to my action servlets or my struts-config
    > file.


    web.xml, a.k.a. the "deployment descriptor", notice the elements
    <session-timeout>
    and
    <welcome-file-list>

    Also, just to help you out, the word "I" should always be capitalized in
    English, and there should be two spaces after the terminal punctuation of each
    sentence. This helps the readability of your posts.

    In fact, generally the purpose of whitespace in text is to enhance readability.

    --
    Lew
     
    Lew, Apr 24, 2007
    #2
    1. Advertising

  3. vyshu

    Guest

    You can use as well

    request.getSession().setMaxInactiveInterval(600);

    the method setMaxInactiveInterval from the class HttpSession.

    But I have problem to forward after the session expiration.
    After the expiration of the session, I can not forward to the login
    page.
    I have set the struts-config.xml for :
    <global-forwards>
    <forward name="welcome" path="/index.jsp"/>
    </global-forwards>

    but in my Action class :

    AccountBean account = (AccountBean)
    httpSession.getAttribute("accessToken");
    if (account == null) {
    //Session expired, go to login page.
    target = "welcome";
    return mapping.findForward(target);
    }

    gives nothing. The view, a .jsp page stays the same without any
    reaction.
    Anyone could help ?
    Thanks
     
    , Apr 25, 2007
    #3
  4. vyshu

    vysh Guest

    On Apr 25, 9:04 pm, wrote:
    > You can use as well
    >
    > request.getSession().setMaxInactiveInterval(600);
    >
    > the method setMaxInactiveInterval from the class HttpSession.
    >
    > But I have problem to forward after the session expiration.
    > After the expiration of the session, I can not forward to the login
    > page.
    > I have set the struts-config.xml for :
    > <global-forwards>
    > <forward name="welcome" path="/index.jsp"/>
    > </global-forwards>
    >
    > but in my Action class :
    >
    > AccountBean account = (AccountBean)
    > httpSession.getAttribute("accessToken");
    > if (account == null) {
    > //Session expired, go to login page.
    > target = "welcome";
    > return mapping.findForward(target);
    >
    > }
    >
    > gives nothing. The view, a .jsp page stays the same without any
    > reaction.
    > Anyone could help ?
    > Thanks


    Have you got any solution for your problem?
    If no,try this.
    Instead of setting the forward action in the global forwards,try
    setting it inside the same action tag.As an action can contain more
    than one forwards,it should not give any problem.
    <action >
    <forward />
    <forward name="welcome" path="/index.jsp"/>
    </action>

    regards,
    vysh
     
    vysh, May 2, 2007
    #4
  5. vyshu

    Tarkin Guest

    On Apr 25, 4:04 pm, wrote:
    > You can use as well
    >
    > request.getSession().setMaxInactiveInterval(600);
    >
    > the method setMaxInactiveInterval from the class HttpSession.
    >
    > But I have problem to forward after the session expiration.
    > After the expiration of the session, I can not forward to the login
    > page.
    > I have set the struts-config.xml for :
    > <global-forwards>
    > <forward name="welcome" path="/index.jsp"/>
    > </global-forwards>
    >
    > but in my Action class :
    >
    > AccountBean account = (AccountBean)
    > httpSession.getAttribute("accessToken");
    > if (account == null) {
    > //Session expired, go to login page.
    > target = "welcome";
    > return mapping.findForward(target);
    >
    > }
    >
    > gives nothing. The view, a .jsp page stays the same without any
    > reaction.
    > Anyone could help ?
    > Thanks


    Unless that is shorthand, the way I learned to
    do struts-config was to map global forwards to
    actions, and then map actions to paths, like this:
    <global-forwards>
    <forward name="foo" path="/Foo.do"/>
    <forward name="bar" path="/Bar.do"/>
    ...
    </global-forwards>
    ....
    <action-mappings>
    <action name="/Foo" path="/path/to/Foo.jsp"/>
    <action name="/Bar" path="/some/other/path/to/Bar.vm"/>
    </action-mappings>
    ....

    HTH,
    Tarkin
     
    Tarkin, May 4, 2007
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Vijay

    Redirecting session expiration

    Vijay, Nov 3, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    353
    Vijay
    Nov 3, 2003
  2. Vijay
    Replies:
    3
    Views:
    1,508
    Saravana [MVP]
    Nov 4, 2003
  3. Replies:
    9
    Views:
    630
    Erwin Moller
    Nov 21, 2003
  4. John
    Replies:
    1
    Views:
    1,572
    Wendy Smoak
    Feb 28, 2005
  5. Praki

    Session Expiration Problem

    Praki, Feb 25, 2008, in forum: Perl Misc
    Replies:
    0
    Views:
    97
    Praki
    Feb 25, 2008
Loading...

Share This Page