I found here code which can solve my problem, but I don't have any idead how it works.
Code:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html>
<head>
<title>Sample Page</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<c:choose>
<c:when test="${pageContext.request.isUserInRole('admin')}">
<p>Content for admin.<p>
</c:when>
<c:when test=${pageContext.request.isUserInRole('someRole')}">
<p>Some content here</p>
<c:when>
<c:otherwise>
<p>Another Content</p>
</c:otherwise>
</c:choose>
</body>
</html>
What I don't know , is how it works pageContext.request.isUserInRole('admin')
.
All my users and user_roles are in database.
So from where does pageContext.request.isUserInRole('admin')
take data?
Can you give me little example how it works and how should I pass information about user role from servlet to pageContext.request.isUserInRole('admin')
.