my dog learned polymorphism*
The moose likes Struts and the fly likes object saved in request/session Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "object saved in request/session" Watch "object saved in request/session" New topic
Author

object saved in request/session

ben oliver
Ranch Hand

Joined: Mar 28, 2006
Posts: 374
In struts 2, Suppose from one action it forwards to a JSP. In the action class it has an instance variable called

List<MyObj> myObjList,

public getMyObjList();
public setMyObjList();

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 ?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

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.
ben oliver
Ranch Hand

Joined: Mar 28, 2006
Posts: 374
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 ?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

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.
ben oliver
Ranch Hand

Joined: Mar 28, 2006
Posts: 374
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 ?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

...

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.
 
jQuery in Action, 2nd edition
 
subject: object saved in request/session
 
Similar Threads
returning comparison counter from collections.sort()
Problem in setting Application scope Object
How do you pass command related parameters from page to page in Spring Web Flow
Is there a default cache?
ejb client