problem with Session expiration in Struts

  • Follow


hi,i have created a small aplication using struts.I just want to know howto give a session timeout for my application.Once the session hasexpired,the user should be redirected to the login page,whenever heclicks on any link or button.It would be really helpful if anyone cangive me the code to be added to my action servlets or my struts-configfile.thanks,vaisakh.
0
Reply vyshu4u (13) 4/24/2007 6:00:54 AM

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
0
Reply Lew 4/24/2007 11:57:03 AM


You can use as wellrequest.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 loginpage.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 anyreaction.Anyone could help ?Thanks
0
Reply aindro 4/25/2007 4:04:05 PM

On Apr 25, 9:04 pm, ain...@gmail.com 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 ?> ThanksHave you got any solution for your problem?If no,try this.Instead of setting the forward action in the global forwards,trysetting it inside the same action tag.As an action can contain morethan one forwards,it should not give any problem.<action >     <forward />     <forward name="welcome" path="/index.jsp"/></action>regards,vysh
0
Reply vysh 5/2/2007 5:51:19 AM

On Apr 25, 4:04 pm, ain...@gmail.com 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 ?> ThanksUnless that is shorthand, the way I learned todo struts-config was to map global forwards toactions, 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
0
Reply Tarkin 5/4/2007 4:55:15 AM

4 Replies
295 Views

(page loaded in 0.472 seconds)


Reply: