I would like to develop a small test multi-login application using Struts2 and JSP. Basically:
-
The application should have welcome page (i.e.
index.jsp) anyone can access. -
This welcome page would have two login boxes: one for users and one for administrators.
-
The web application should have two sub-applications, one for users, one for administrator. In other words, it is not a single application where logged-in users would have different privileges. Each sub-application would have their own secluded set of pages.
Struts2 uses the MVC pattern and I am wondering how I should use the filter pattern to organize this. I could have all requests under /userapp/* go to the user application and all requests under /adminapp/* go to the admin application.
My questions are:
-
Is this the right strategy (i.e. best practice)? If yes, how should I implement this in my
web.xml? -
Should I implement two filters and two mappings (if yes why?) or should I implement one filter and two mappings?
UPDATE
After doing a lot of reading, I get to understand that Struts2 multi-login is an over-engineered and too heavy solution for what I need. I have decided to implement my own Servlet 3.0 and use JQuery + Ajax.
Consider a case where there are 2 different users ‘Admin'(Highest Privileges) and ‘Customer(Less Privileges compared to Admin)’. In Struts,you can implement like this
1.Make a Business Logic like
Userclass which basically does the following tasks2.Use this ‘User’ object from within ‘Action’ class.So,you pass the ‘ActionForm’ values(username,password) into this business method,validate the user and get a specific usertype(Storing in session).
3.On subsequent requests made by this ‘User’,check the usertype and forward accordingly.Create a custom ‘Action’ class which always validates the usertype(and other validations) on each action received from a usertype. All your other ‘Action’ class should extend this custom ‘Action’ class.
This is how i implemented in one of the my Struts web-application where more than 3 types of users with different rights.I never seen a separate url pattern for each user type.So it is better to show,
http://www.yoursite.com/Process.actioninstead of
http://www.yoursite.com/adminapp/Process.action