1

我们正在使用 Struts2 和 GWT-EXT。

我们已经创建了一个 LoginInterceptor,它将在执行某些受限任务之前被调用。

下面是 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;
        }       
    }

会话超时后.. 如果用户单击任何按钮。在继续之前 LoginInterceptor 被调用并检查用户是否登录。

在代码中

我们有一个方法 public void onFailure(Throwable caught) {

我在哪里检查

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(){ 
                    public void execute(){ 
                        History.newItem(HistoryToken.INDEX_PAGE.toString());
                    } 
                }); 

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

然后,我将其重定向到索引页面。

这在托管模式下的 Eclipse 中可以正常工作,但是当我创建 .war 并在 JBoss 中运行它时。它没有进入onFailure方法并直接重定向到索引页面。

4

1 回答 1

1

喂...

在调用异常代码之前尝试此代码。之前if (caught instanceof InvocationException) { 的条件......

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());
            } 
        }); 

    }
于 2011-04-21T04:56:50.810 回答