开发者

Redirect to Index page after session timeout not working in .war

We are using Struts2 & GWT-EXT.

We have crated a LoginInterceptor which will be called before performing certain restricted tasks.

Here is the method of LoginInterceptor

public String intercept(ActionInvocation arg0) throws Exception {

        try
        {
            System.err.println("inside the login interceptor");
            Map session = arg0.getInvocationContext().getSession();
            User loggedInUser = (User)session.get("loggedInUser");

            if(loggedInUser != null)
            {

                return arg0.invoke();
            }else {

                throw new AuthorizationException("unAuthorized");               
            }

        }catch (Exception e) {          
            throw e;
        }       
    }

After session timout.. If a user clicks on any button. Before proceeding LoginInterceptor gets called and checks whethere user is logged in or not.

In the code

We have a method public void onFailure(Throwable caught) {

where i check that

if (caught instanceof InvocationException) {
        if (caught instanceof StatusCodeException
                && caught.getMessage().contains(
                    "<title>Error 500 unAuthorized</title>")) {
            MessageBox.alert("Session Expired", "Session has been expired. Press Ok to redirect to Login page.", new AlertCallback(){ 
           开发者_如何学C         public void execute(){ 
                        History.newItem(HistoryToken.INDEX_PAGE.toString());
                    } 
                }); 

        } else if (caught.getMessage().contains("LoginInterceptor")) {
            History.newItem(HistoryToken.INDEX_PAGE.toString(), true);
        }

Then, I redirect it to Index Page.

This works in Eclipse fine in Hosted Mode but when I create .war and run it in JBoss. It does not comes into onFailure method and gets redirected directly to Index Page.


Hiii...

try this code just before the invocation exception code. before if (caught instanceof InvocationException) { condition....

if(caught.getMessage().contains("unAuthorized") )
    {
        MessageBox.alert("Session Expired", "Session has been expired. Press Ok to redirect to Login page.", new AlertCallback(){ 
            public void execute(){ 
                History.newItem(HistoryToken.INDEX_PAGE.toString());
            } 
        }); 

    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜