Tomcat Interview Questions and Answers
Question: How can I access members of a custom Realm or Principal?Answer: When you create a custom subclass of RealmBase or GenericPrincipal and attempt to use those classes in your webapp code, you'll probably have problems with ClassCastException. This is because the instance returned by request.getUserPrincipal() is of a class loaded by the server's classloader, and you are trying to access it through you webapp's classloader. While the classes maybe otherwise exactly the same, different (sibling) classloaders makes them different classes.This assumes you created a My Principal class, and put in Tomcat's server/classes (or lib) directory, as well as in your webapp's WEB-INF/classes (or lib) directory. Normally, you would put custom realm and principal classes in the server directory because they depend on other classes there. Here's what you would like to do, but it throws ClassCastException: MyPrincipal p = request.getUserPrincipal(); String emailAddress = p.getEmailAddress(); Here are 4 ways you might get around the classloader boundary:
|
Is it helpful?
Yes
No
Most helpful rated by users:
- What is Tomcat?
- How do you create multiple virtual hosts?
- How do I override the default home page loaded by Tomcat?
- What is Jasper?
- Question : How to communicate between two webservers in two diff systems?