weixin_33698823 2013-11-06 12:31 采纳率: 0%
浏览 32

Struts2 Ajax问题

The problem is the following. When user clicks on the link I load the data into a div, but when the session of the user is expired I need to redirect him to login page, or if the is external error I need to redirect the user to error page. The problem is, if for example my interceptor sees that the user is no longer in session and tries to redirect him to login page, the login page is again loaded in the div. the other elements on page remain. How can I make the page reload without JavaScript? I mean directly from struts.xml.

  • 写回答

1条回答 默认 最新

  • weixin_33725239 2013-11-06 17:21
    关注

    You need to send to your browser whether it is a new session or not.

    One way.

    In your interceptor add a header to indicate whether it is a new session. Then if you are using jquery you can bind the ajax complete and check the header for the attribute that its a new session. And finally on new session, do a location.reload.

    your ajax for jquery would look something like this

        jQuery(document).ajaxComplete(function(e, xhr, settings) {
    
            var status = xhr.status;
            if(status == 200 ){
                var isAuth = xhr.getResponseHeader('_isnewsession');
    
                if((isAuth == '1')){
                    alert('Your Session has timed out!');
                    location.reload();
                }
            }
        });
    

    Does that make sense?

    评论

报告相同问题?

悬赏问题

  • ¥50 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?