方法有两种:
假设,此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"); } %>