This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
In struts 2, Suppose from one action it forwards to a JSP. In the action class it has an instance variable called
In JSP we can access this "myObjList". Now, what if somehow in the session we have also set such an attribute called "myObjList" and it was set before we reach the action class. And suppose that what we set in the session for "myObjList" is different from what is set in the action class, then in the JSP, will it just get what's set in the action and ignore the session's object ?
Seems like it would just be quicker to try it and see what happens.
Unless you're using Spring to automagically inject web-scoped objects there'd be no reason for S2 to put a session value into an action.
Joined: Mar 28, 2006
Actually I have tried when I posted my question. It got the object I set in Action class without problem. But, there is something that I do not know how to try --- I don't know the behind scene procedure how struts look for the object. When JSP retrieves an object, does it
1) First check from the Action (request) or first check from session ?
2) if it checks from Action and can not find the object, does it automatically search the session ? If it finds the object from Action, does it continue to search it from session ?
If you're using an S2 tag it will search only the value stack. If you're using JSP EL it will first search the value stack and if not found, call the default JSP scope lookup, searching the normal scopes.
Joined: Mar 28, 2006
David Newton wrote:If you're using an S2 tag it will search only the value stack. If you're using JSP EL it will first search the value stack and if not found, call the default JSP scope lookup, searching the normal scopes.
I use struts 2. In value stack, it has all the objects stack, but also has context map including request and session. So, I guess this still does not answer my question --- In my case, if I have object in the Action class, is the object automatically saved in the object stack ?? If yes, once it is found there, will it still continue to search the context map to see if there is same named object saved there ?
The action is pushed onto the stack for use in the result page (like a JSP). It's not that individual action properties are saved on the stack: the entire action is on the stack.
I already told you the order in which things are searched. The first object found will be the one returned: as I stated, if it's found on the value stack, it's returned. After that the default JEE scope search is executed, with identical semantics: it *is* the default JEE process.
See the StrutsRequestWrapper source if I have not been convincing enough.
Are you asking to satisfy your curiosity? If so, looking at the source will be more efficient than this. If not, and you're having a specific issue, let's deal with the specific issue.