Struts 2 session management and dynamically displaying jsps

独自空忆成欢 提交于 2019-12-08 04:46:41

问题


I am writing an app using Struts 2 framework. It has a login page with username, password and usertype (ex. Administrator, supervisor, analyst etc.)

I want to do two things:

  • Session management - logging out, timed logout etc.
  • Display different pages to different users based on the user type.

Any help on either/both is highly appreciated.


回答1:


for the first part struts2 already provides out of the box session management all you have to do is to use session aware and let struts2 handle the rest of the work for you.doing login and log out are your own preferred way to implement them, though you can use interceptor to check if the user is logged in or not etc.

your second part is much like a user access and right management and i believe spring security module is the best approach to achieve such goal Spring Security




回答2:


your second part is much like a user access and right management and i believe spring security module is the best approach to achieve such goal Spring Security

This is one approach, however it also requires learning another framework on top of Struts.

In this type of application I would personally implement a UserInfo object to maintain in session with an account type field for basing conditional operations on. For instance, a super user account would simply have a boolean with a getter user.isSuperUser().

In doing this you can stick the UserInfo object in session and use struts tags to include different pages, for example:

<s:if test="%{#session.user.SuperUser}">
   <s:include value="superUser.jsp" />
</s:if><s:else>
   <s:include value="regularUser.jsp" />
</s:else>


来源:https://stackoverflow.com/questions/6906894/struts-2-session-management-and-dynamically-displaying-jsps

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!