加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

java – 如何防止访客用户访问管理页面

发布时间:2020-12-15 04:32:38 所属栏目:Java 来源:网络整理
导读:我试图阻止访客用户访问管理页面. 这是我为admin捕获角色1而为guest捕获0的位置. %HttpSession session = request.getSession();String sessionVal= (String)session .getAttribute("loggedIn");int role = (Integer)session .getAttribute("role");System.o
我试图阻止访客用户访问管理页面.
这是我为admin捕获角色1而为guest捕获0的位置.

<%
HttpSession session = request.getSession();
String sessionVal= (String)session .getAttribute("loggedIn");
int role = (Integer)session .getAttribute("role");
System.out.println(" role "+ role);
if(sessionVal == null)
{
	response.sendRedirect("/project/pages/login.jsp");
}
else
{
%>
      // All html code goes here

这是用于导航的html代码

<ul id="nav">
	<li><a href="/project/pages/home.jsp">Dashboard</a></li>
	<li ><a href="/project/pages/profile.jsp">Profile</a></li>					
	<li><a href="/project/pages/setting.jsp">Setting</a></li>									<li><a href="/project/pages/admin.jsp">Admin</a></li>
</ul>

现在如何阻止访客用户(角色== 0)访问管理页面.或者如果role == 0我如何隐藏admin.jsp.

解决方法

为什么不

if(sessionVal == null || role == 0)

隐藏JSP中的链接

<%
HttpSession session = request.getSession();
int role = (Integer)session .getAttribute("role");
System.out.println(" role "+ role);
if(role != 0)
{
 %>
    <a href="admin.jsp">Top Secret Link</a>
 <%
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读