session过期后,如何让当前页面回到登录页面??请帮忙给出具体代码好吗?谢谢!!

解决方案 »

  1.   

    直接解这道题我没有答案
    但是否可以考虑换种思考方式,
    做个过滤器,在用户发送下一个request的时候,如果该session为空,就返回?
    (实际上你要控制的是用户的登陆吗?)
      

  2.   

    是设置了session,过期后,页面就变成了错误的页面,是个问题。所以,但session过期后,回到登录页面,但不知怎么做
      

  3.   

    session后,session中没有登录的记录,这里forward到登录就ok了吧.难的是怎么记住最后一页在哪里.
      

  4.   

    新建一个JSP,里面判断session是否过期,如果过期就返回登录页面。
    然后在你的其它的JSP中用include这个JSP
      

  5.   

    首先设置session过期的时间,然后在公共模块里判断,如果时间大于session过期时间,则回到登录页面,看看你登录csdn时两秒后自动跳转,和你的是一个道理!
      

  6.   

    首先在用户身份验证的页面里将登录时的用户信息绑定到session上:(如)
            
             //user = request.getParameter("su_id");
    //passwd = request.getParameter("su_pwd");  
             session.setAttribute("UserName", user);
    然后把下面的JSP内容直接添加或incluse到需要验证的页面中。<%
    String userName = (String)session.getAttribute("UserName");
    if(userName == null)
    {
      %>
      <script>
        alert("请先登录!");
        window.top.location.href='../index.htm';
        </script>
        <%
      }
    %>
      

  7.   

    加入验证机制,对url授权
    session过期就没有访问的权利,就能转到登陆页面
      

  8.   

    新建一个JSP,里面判断session是否过期,如果过期就返回登录页面。
    然后在你的其它的JSP中用include这个JSP这个想法是正确的.
      

  9.   

    用个Bean 不过,还是要建个JSP判断文件
      

  10.   

    方法
    1,使用过滤器,判断session过期,就转到某页。
    方法
    2,定义一个BaseAction , excute()判断session过期,就转到某页,你所有的Action继承此类,
    BaseAction
    {
        excute(...){
         ....
        excuteAction();
       }
    }Acion子类覆写excuteAction()就好了。
    也就是这两个办法。
    -----------srx(好读书,不求甚解,每有会意,欣然忘食) (
      

  11.   

    public void doFilter(ServletRequest request,ServletResponse response,FilterChain chain)
        throws ServletException, IOException {
            String strReqPage="";
            HttpServletRequest req=null;       
            if (request instanceof HttpServletRequest) {
                req=(HttpServletRequest)request;
                strReqPage = req.getRequestURI();
                //ログインかのを確認する            if(strReqPage.indexOf("/faces/jsp/")>0&&strReqPage.indexOf("CO001")<0){
                    SessionBeanUserInf ssnUsrInf = (SessionBeanUserInf)req.getSession().getAttribute("SessionBeanUserInf");
                    if(ssnUsrInf==null ||!ssnUsrInf.getLogined()){
                        if(!(strReqPage.indexOf("ERROR_SG")>0&&req.getParameter("mesgId")!=null)){
                            //ログイン画面に戻る                        request.getRequestDispatcher("index.html").forward(request, response);
                            return;
                        }
                    }else if(ssnUsrInf!=null&&ssnUsrInf.getLogined()&&strReqPage.indexOf("CO002")<0){
    //アクセスの権限を検証する
    if((strReqPage.indexOf("TR001")>0&&"0".equals(ssnUsrInf.getUserAcessAuthority()[0]))
    ||(strReqPage.indexOf("TR002")>0&&"0".equals(ssnUsrInf.getUserAcessAuthority()[1]))
    ||(strReqPage.indexOf("AD001")>0&&"0".equals(ssnUsrInf.getUserAcessAuthority()[2]))
    ||(strReqPage.indexOf("GR001")>0&&"0".equals(ssnUsrInf.getUserAcessAuthority()[3]))
    ||(strReqPage.indexOf("GR003")>0&&"0".equals(ssnUsrInf.getUserAcessAuthority()[4]))
    ||(strReqPage.indexOf("GR005")>0&&"0".equals(ssnUsrInf.getUserAcessAuthority()[5]))
    ||(strReqPage.indexOf("temp")>0&&"0".equals(ssnUsrInf.getUserAcessAuthority()[6]))){
                            //メーンメニュー画面に戻る                        request.getRequestDispatcher("CO002.jsp").forward(request, response);
                            return;
    }

    }
                    //ApplicationBean をとる                Object appObj=req.getSession().getServletContext().getAttribute("ApplicationBean");                 
                    if(appObj!=null&& appObj instanceof  ApplicationBean
    &&ssnUsrInf!=null&&ssnUsrInf.getUserId()!=null){
                        ApplicationBean appBean=(ApplicationBean)appObj;
                        HashMap userMap=appBean.getUserMap();
                        //ユーザーリストに該当ユーザーを                    if(userMap!=null&&userMap.containsKey(ssnUsrInf.getUserId())){
                            if(!userMap.get(ssnUsrInf.getUserId()).equals(ssnUsrInf.getUserIP())){
                                //ログイン画面に戻る                            request.getRequestDispatcher("ERROR_SG.jsp?mesgId=ERS010").forward(request, response);
                            }
                        }                    
                    }                
                }
            }
            chain.doFilter(request, response);
        }