• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

Struts 2 and Session Timeout

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I want to redirect the user to an error page if session will be timed out. How can I achive this? I have tried the following options.

1. Is there any inbuilt interceptor for checking session timed out , I believe no.
2. I have created one custom Interceptor, which simply checks whether the session is null or not before the execute() method will be executed. If the session is null the custome interceptor will throw exception. It was working fine , but in one jsp, where I'm using request obejct to put some data , found that the request object reference becomes null. But while not using the interceptor, the jsp is wokring fine, though the action class was requestaware.
3. Can I use any listner?

Please help me out.

Thanks
/Abhi

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Answer for Q1 - No (i am not sure)

Answer for Q2:

i also doing like that what you mentioned.

before that, you should configure the interceptor as default-interceptor

please do the following steps:

1). interceptor.

public String intercept(ActionInvocation actionInvocation) throws Exception {
ActionContext context = actionInvocation.getInvocationContext();
Map<String, Object> sessionMap = context.getSession();
//System.out.println(" retrived session "+ sessionMap);
if(sessionMap == null
|| sessionMap.isEmpty()
|| sessionMap.get("SESSION_SERVICE") == null) {
System.out.println(" session expired...");
return "SESSION_EXPIRED";
}

String actionResult = actionInvocation.invoke();

return actionResult;
}


SESSION_SERVICE - one of the attribute we are setting after user login.
if the session expired, session object will be null [if struts creates the session object our attribute won't be there]

2). struts.xml


<interceptors>
<interceptor name="tstSessionInterceptor" class="package.SessionInterceptor"/>

<interceptor-stack name="tstSessionCheckStack">
<interceptor-ref name="tstSessionInterceptor" />
<interceptor-ref name="defaultStack" />
</interceptor-stack>
</interceptors>

<default-interceptor-ref name="tstSessionCheckStack"/>

</global-results>
<result name="sessionexpired" >sessionexpired.jsp</result>
</global-results>



thats what i have implemented.

it's working fine.

please revert back, if any issues.

thanks
 
Ranch Hand
Posts: 83
Spring Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I dont think there any interceptor like that. But you can easily write your own.

Checkout this Struts2 Interceptor


_______________________________________________
Try Struts 2
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ariram Kalimuthu wrote:Answer for Q1 - No (i am not sure)

Answer for Q2:

i also doing like that what you mentioned.

before that, you should configure the interceptor as default-interceptor

please do the following steps:

1). interceptor.

public String intercept(ActionInvocation actionInvocation) throws Exception {
ActionContext context = actionInvocation.getInvocationContext();
Map<String, Object> sessionMap = context.getSession();
//System.out.println(" retrived session "+ sessionMap);
if(sessionMap == null
|| sessionMap.isEmpty()
|| sessionMap.get("SESSION_SERVICE") == null) {
System.out.println(" session expired...");
return "SESSION_EXPIRED";
}

String actionResult = actionInvocation.invoke();

return actionResult;
}


SESSION_SERVICE - one of the attribute we are setting after user login.
if the session expired, session object will be null [if struts creates the session object our attribute won't be there]

2). struts.xml


<interceptors>
<interceptor name="tstSessionInterceptor" class="package.SessionInterceptor"/>

<interceptor-stack name="tstSessionCheckStack">
<interceptor-ref name="tstSessionInterceptor" />
<interceptor-ref name="defaultStack" />
</interceptor-stack>
</interceptors>

<default-interceptor-ref name="tstSessionCheckStack"/>

</global-results>
<result name="sessionexpired" >sessionexpired.jsp</result>
</global-results>



thats what i have implemented.

it's working fine.

please revert back, if any issues.

thanks






This code is not running properly...actually i want the show the message after session time out....please help me out of this...........My LoginAction page coding is:---

package com;

import java.util.Map;

import org.apache.struts2.dispatcher.SessionMap;
import org.apache.struts2.interceptor.SessionAware;

import com.opensymphony.xwork2.ActionSupport;


public class Login extends ActionSupport implements SessionAware{

private String username,userpass;
SessionMap<String,String> sessionmap;

public String getUsername() {
return username;
}

public void setUsername(String username) {
this.username = username;
}

public String getUserpass() {
return userpass;
}

public void setUserpass(String userpass) {
this.userpass = userpass;
}

public String execute(){

if(LoginDao.validate(username, userpass)){
return "success";
}
else{
return "error";
}
}

public void setSession(Map map) {
sessionmap=(SessionMap)map;
sessionmap.put("login","true");
}

public String logout(){
sessionmap.invalidate();
return "success";
}

}


.......
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Abhi Roy wrote:Hello,
I want to redirect the user to an error page if session will be timed out. How can I achive this? I have tried the following options.



The easiest thing to do is to use the security API that is already built into JEE servers. start reading here.
 
Get off me! Here, read this tiny ad:
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic