开发者

How to configure web.xml for multiple login in a Struts2 web application?

开发者 https://www.devze.com 2023-04-09 00:33 出处:网络
I would like to develop a small test multi-login application using开发者_运维知识库 Struts2 and JSP. Basically:

I would like to develop a small test multi-login application using开发者_运维知识库 Struts2 and JSP. Basically:

  1. The application should have welcome page (i.e. index.jsp) anyone can access.

  2. This welcome page would have two login boxes: one for users and one for administrators.

  3. 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:

  1. Is this the right strategy (i.e. best practice)? If yes, how should I implement this in my web.xml?

  2. 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 User class which basically does the following tasks

  a.)Gets the username,password as input.
  b.)Checks whether this 'username' exists in database.
  c.)If exits, gets the type of user(either Admin or Customer) and checking 
     its corresponding password.

2.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.action instead of http://www.yoursite.com/adminapp/Process.action

0

精彩评论

暂无评论...
验证码 换一张
取 消