Reputation: 10395
I found this answer very usefull but I can't figure out why it works.
In accordance with API pageContext getRequest() method returns ServletRequest and it doesn't contain getUserPrincipal() method. So why do things like this work
<c:if test="${not empty pageContext.request.userPrincipal}">
<c:if test="${pageContext.request.isUserInRole('ADMIN')}">
User ${pageContext.request.userPrincipal.name} in ADMIN Group
</c:if>
</c:if>
Is there implicit type conversion or what?
Upvotes: 1
Views: 872
Reputation: 691745
The servlet API has been designed, a long time ago, in order to be usable in a context that is different from a web, HTTP context (I think supporting WAP using this API was a goal, at that time).
In reality, I don't know of any context other that the traditional Java EE webapp context where the servlet API is used. And in that context, all requests are instances of HttpServletRequest (which is a sub-interface of ServletRequest). And this method exists in HttpServletRequest.
Upvotes: 3