Welcome to WebmasterWorld Guest from 18.104.22.168
Forum Moderators: phranque
Very quick question - this must be a really common thing, I just can't figure it out. How do you gain access to the Session from within the ActionForm itself?
I have a struts application. I have a jsp page, with it's own Action and ActionForm.
Now, when a button is pressed, it fires the execute method in its Action, of which one of the parameters is an instance of HttpServletRequest, from which the session can be reached.
My problem isn't at this stage though. I need to access the session when the page is first loaded, before the user clicks on anything at all, ie, when the page is being initialised, basically to prepopulate the page.
In the ActionForm, I can preset its properties by using its default constructor, but I cannot figure out how to get to the session.
Do you have to pass it along from the previously-accessed page when you are redirecting to this page? Is there a specific method call I need to make? Or am I looking in completely the wrong place?
Any advice will be greatly appreciated - I know this can be done, and it's driving me mad, that I can't do it!
Thanks - if you need further clarification, just let me know.
*EDIT - Apologies if this is in the wrong forum...still can't seem to find the right one for Java issues!
A hint for anyone else in the same situation - use the ActionForm's Reset method.
public void reset(ActionMapping mapping, HttpServletRequest request)
This is run when the page is first created, and guess what, you've got access to the happy little request object there!