I am new to use session management & I am using struts with MySQL as backend. I am developing a simple timesheet application. My requirement is like when a user login succesfully in login page, he should be able to add the work or tasks done that are saved in the session scope of that user. Similarly he should be able to see only his timesheet data like a normal session scoped retrieval of data from database. Is it possible to use JSTL tags for session scoped backend interaction without Action class(Java Source). Pls tell a easy detailed proceedure from start to end about implementing this.
I am confused that how all users data stored in one table or database can be made to work in user session scope. If not, how should data be stored(seperate for each user ?) Plz explain.
It’s quite simple actually.
With Struts, each request goes to the Struts servlet, which dispatches it to a Struts action.
The Struts action gets input data coming from the user from the action form. It also has access to the session. And with all this information, it can get data from the database, and store this data (as Java Beans) into request attributes.
The action then returns an action forward and the Struts servlet forwards the request to the corresponding JSP page. This JSP page generates HTML using the data stored in the request attributes by the action.
So, after the login, you should have the ID of the authenticated user in the session. The action can use this user ID to get data from the database belonging to this user:
Don’t try to get data from the database in the JSPs. JSPs should only generate HTML. It’s the job of the Java code, called from the action class, to get the user ID from the session and to get data from the database using this user ID. That’s the whole point of the MVC pattern promoted by Struts.