I have a JSP struts application that uses Spring to integrate with / dao / database services. Basically, struts uses Spring to get data from the database, it creates a form and redirects it to JSP files.
I have a header file that is entered in each JSP file using Tiles. I would like to show "Welcome John Doe" on every page inside the headline. Where "John Doe" is the name of the user currently registered.
What would be the best way to do this? The solution I can think of is:
Use Spring. Filter out HTTP request trapping. Download the user from the database using a cookie that contains the user ID (*) and place it in a bean session called "CurrentUser"
In "header.jsp" find the context of the Spring application. Using it, load the "CurrentUser" bean and get the name. Put the name in html.
I think I can make it work. But I'm not sure if this is the best way to do this. Any thought on my approach?
(*) Of course, the cookie will be encrypted
source
share