Struts 2 会话管理和动态显示jsps

Struts 2 会话管理和动态显示jsps

问题描述:

我正在使用 Struts 2 框架编写应用程序.它有一个包含用户名、密码和用户类型(例如管理员、主管、分析师等)的登录页面

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

我想做两件事:

  • 会话管理 - 注销、定时注销等
  • 根据用户类型向不同的用户显示不同的页面.

非常感谢您对其中一个/两个方面的任何帮助.

Any help on either/both is highly appreciated.

您的第二部分很像用户访问和权限管理,我相信 Spring Security 模块是实现这一目标的最佳方法 Spring Security

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

这是一种方法,但它也需要在 Struts 之上学习另一个框架.

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

在这种类型的应用程序中,我将亲自实现一个 UserInfo 对象,以与帐户类型字段保持会话,以进行条件操作.例如,一个超级用户帐户只会有一个带有 getter user.isSuperUser() 的布尔值.

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().

这样做时,您可以将 UserInfo 对象粘贴到会话中并使用 struts 标签来包含不同的页面,例如:

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>