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 @ 2015-02-28 18:54  koal  阅读(711)  评论(0编辑  收藏  举报