| Author |
how can we use struts to issue a session scope preparation ?
|
Edward Chen
Ranch Hand
Joined: Dec 23, 2003
Posts: 758
|
|
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
|
 |
Marc Peabody
pie sneak
Sheriff
Joined: Feb 05, 2003
Posts: 4725
|
|
|
I think that what you are describing is usually done in the InitialAction, or whichever action the user first enters in the application.
|
A good workman is known by his tools.
|
 |
Kevin Judd
Greenhorn
Joined: Dec 02, 2004
Posts: 9
|
|
Take a look at Rick Reumann's site. He as lots of good examples, all well annotated: http://www.reumann.net/struts/lesson2/step9.do Good luck.
|
Kevin Judd, SCJP
|
 |
Edward Chen
Ranch Hand
Joined: Dec 23, 2003
Posts: 758
|
|
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. Thanks.
|
 |
Edward Chen
Ranch Hand
Joined: Dec 23, 2003
Posts: 758
|
|
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 ? Thanks
|
 |
Marc Peabody
pie sneak
Sheriff
Joined: Feb 05, 2003
Posts: 4725
|
|
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.
|
 |
Edward Chen
Ranch Hand
Joined: Dec 23, 2003
Posts: 758
|
|
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. Thanks.
|
 |
 |
|
|
subject: how can we use struts to issue a session scope preparation ?
|
|
|