• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 201
  • Last Modified:

detecting role-name in java bean


This is variation of my previous problem.
Create a servlet that reads request parameter from the user, creates a prime umber of the specified size, and forwards the request to a JSP page that displays the result. If no size if specified, display a 30-digit prime. Use MVC to display it. Only administrators should see primes of 40 digits or more. If ordinary users ask for primes of 40 or more digits, they should get 20-digit primes instead.

My question is how can I detect role-name in java bean? Another words, after users login, I want to detect whether administrator login or not.

(form-based authenticaiton was used.)

2 Solutions
Dear dkim18,

Try this API.

Package javax.servlet.http
Interface HttpServletRequest

public boolean isUserInRole(java.lang.String role)

Returns a boolean indicating whether the authenticated user is included in the specified logical "role". Roles and role membership can be defined using deployment descriptors. If the user has not been authenticated, the method returns false.
role - a String specifying the name of the role
a boolean indicating whether the user making this request belongs to a given role; false if the user has not been authenticated

Best luck,


Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now