会话超时后重定向到索引页面在 .war 中不起作用

发布于 2024-11-01 05:07:38 字数 1713 浏览 1 评论 0原文

我们正在使用 Struts2 和 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 catch) {

我在其中检查

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 方法并直接重定向到索引页。

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(){ 
                    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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

↙厌世 2024-11-08 05:07:38

嗨...

在调用异常代码之前尝试此代码。 before if (caughtinstanceof InitationException) {
健康)状况....

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

    }

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

    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文