jsp判断session中的值

方法有两种:

假设,此session的名字叫adminAccount

1、EL表达式

  <script type="text/javascript">
       if($.trim("${sessionScope.adminAccount}") == "")
       {
             top.location.href="admin.jsp";
       }
  </script>

2、java代码

  <%
       if(session.getAttribute("adminAccount")==null || session.getAttribute("adminAccount")=="")

       {
             String path = request.getContextPath();
             String basePath = request.getScheme() + "://"+ request.getServerName() + ":" + request.getServerPort()+ path + "/";
             response.sendRedirect(basePath+"admin.jsp");
       }
  %>

posted on 2013-11-28 13:45  专注2018  阅读(4197)  评论(0编辑  收藏  举报