How can I create a session-scope object when user session is created in the struts ?
Say, I have a variable which need to be created when session is created. In the plain servlet, we can write a session listener to issue a session scope preparation, for example, getting a datasource.
Now I try same way in Struts, but it doesn't work. I guess, Strtus create session even before it passes events to session listener, so we can't see any output. But we tell the variable is being added to session.
Anyway, how can we use struts to issue a session scope preparation ?
Thanks, Kevin. I have read this link. I realize one difference.
What that link did is , "Before we forward directly to the employeeForm.jsp " ...., then it does some session-scope setup. But the problem is , user has to invoke that /setupEmployeeForm.do, then it will work. Now I have to do this session-scope setup without any user's interaction, just like in Java, we have a globe static variable during compilation.
This is my problem.
Joined: Dec 23, 2003
Originally posted by Marc Peabody: I think that what you are describing is usually done in the InitialAction, or whichever action the user first enters in the application.
Thanks, Marc, which file is InitialAction in, so that I can extend that class file? Do you have some examples or link ?
An InitialAction is one that you create. It is like a SetupAction for the user's session.
Most often, it is used as the single entry point into an application (the first one the user enters). Sometimes the welcome page of a WebContext does an automatic redirect to such an action.
You can't have a session-setup without user interaction as you described. If a user does not enter [or interact with] an application they do not get a session.
Joined: Dec 23, 2003
After searching web and reading your guys post, I found these two solutions for preparing for session-scope variable.
1. use traditional session event listener. When page is loaded up first time, Struts always create a session for the user, even before it gets form bean variable value. In the session listener, we can issue some data, for example, jdbc connection.
2. extends RequestProcessor, override its method processPreprocess(...). When each time user click some action, it will always run processPreprocess() firstly. So we can do something there, for example, JDBC connection.
If anything wrong, please correct me. This is just my research.