my dog learned polymorphism
The moose likes Struts and the fly likes prepare() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "prepare() " Watch "prepare() " New topic


ben oliver
Ranch Hand

Joined: Mar 28, 2006
Posts: 375

In my struts.xml I have URL link /app/test/ maps to test() method. I found when I type /app/test?name=xyz&ID=ABC
it went throught the prepare() method, but inside the method it recognizes "name" and "ID" as null, i.e. the values of name and id are not bounded to the instance variable yet. However, in "test()" these values are avaiable already.

Can you tell me why ? And how can I do some cleaning type work in "prepare()" that needs to use instance variables ?

secondly, if instance variables are not available in prepare(), are session variables available ?

Thank you.
Mohana Rao Sv
Ranch Hand

Joined: Aug 01, 2007
Posts: 485

Prepare method will be called before you action triggers, so using the parameterAware in prepare method read request Parameters and assign the values. To take care order of interceptors. ServletConfig should be before PreparableInterceptor.

ocjp 6 — Feeding a person with food is a great thing in this world. Feeding the same person by transferring the knowledge is far more better thing. The reason is the amount of satisfaction which we get through food is of only one minute or two. But the satisfaction which we can get through the knowledge is of life long.
I agree. Here's the link:
subject: prepare()
jQuery in Action, 3rd edition