I have a JSP struts application that uses Spring to integrate with the services/dao/database. Basically, struts uses spring to get the data from the DB, it builds the form and forward them to the JSP files.
我有一个通过Tiles注入到每个JSP文件中的头文件。我希望在头文件内的每页上显示“欢迎John Doe”。其中,“John Doe”是当前登录用户的名称。
What would be the best approach to do that? The solution that I can think of is:
使用Spring过滤器来捕获http请求。使用包含用户ID(*)的cookie从数据库中加载用户,并将名称放置在名为“CurrentUser”的会话Bean中。 (*)用户ID - 用户的唯一标识符。
在“header.jsp”中获取Spring应用程序上下文。使用它加载“CurrentUser” bean并获取名称。将名称放入HTML中。
I think I could get this to work. But I m not certain this is the best way to do it. Any thought on my approach?
当然,这个cookie将被加密。