Netbeans判断session过期跳转到登陆页

Netbeans下visual web pack开发时候 用到了判断session 是否过期,过期就跳转到登陆页面

判断session过期代码如下:

 //得到请求实例
        HttpServletRequest request = (HttpServletRequest)this.getFacesContext().getExternalContext().getRequest();
        //得到session实例
        HttpSession session = request.getSession(false);
        //如果session过期
        if (session.getAttribute("sGrants") == null)
        {
            try {
                //跳到登陆页面
                FacesContext.getCurrentInstance().getExternalContext().redirect("../default.jsp");
                //返回
                return ;
            } catch (Exception ex) {
                //打印异常信息
                ex.printStackTrace();
            }
        }

登陆页面代码:

<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%
response.setHeader("progma","no-cache");
response.setHeader("Cache-Control","no-cache");
response.setDateHeader("Expires",0);
if(session.getAttribute("sGrants") != null){
session.setAttribute("sGrants",null);
}
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>人力资源管理系统登录</title>
        <link href="style/main.css" rel="stylesheet" type="text/css" />
        <link href="style/login.css" rel="stylesheet" type="text/css" />
        <script type="text/javascript" language="javascript">
            function cc(){
                 CollectGarbage();
                 window.opener = null;
                 window.close();
            }
           if(top.location !== self.location) {
               top.location=self.location;
           }
           self.moveTo(0,0)
           self.resizeTo(screen.availWidth,screen.availHeight)
        </script>
   <script language="javascript" type="text/javascript" src="js/check.js"></script>
    </head>
    <body>
 <f:view>
  <h:form>       
<div class="logo"><img src="images/l_1.gif" /></div>
<div class="l_top"></div>
<div class="l_box">
<div class="login">   
        <table cellpadding="4">
            <tr>
                <td align="right">用户名</td>
                <td>
                    <h:inputText id="loginName" required="true"   validator="#{validator.validateName}" style="width:175px;"/>
                    <h:message for="loginName" showDetail="" showSummary="true" style="color: #ff0000; "/>
                </td>
                   
            </tr>
            <tr>
                <td align="right">密&nbsp;&nbsp;&nbsp;&nbsp;码</td>
                <td><h:inputSecret id="loginPass" required="true" validator="#{validator.validatePass}"  style="width:175px;"/>
                    <h:message for="loginPass" showDetail="" showSummary="true" style="color: #ff0000; "/>
            </td>
                
            </tr>
            <tr>
                <td>&nbsp;</td>
                <td><h:commandButton image="images/l_3.gif" value="登陆" action="#{validator.button2_action}" οnclick="return s();"/>
                    <h:commandButton image="images/l_3_c.gif" value="取消" οnclick="cc();"/>
                </td>
            </tr>      

        </table>
  </div>
</div>
<div class="l_foot"></div>   
  </h:form>
 </f:view>
    </body>
</html>

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值