locconfused
locconfused

Reputation: 59

struts2 getting value in action class

<action name="Locator" method="execute" class="LocatorAction">
        <result name="success">/locator/StoreInfo.jsp</result>          
    </action>

I have a variable foo in LocatorAction class and I want to display it on my result jsp, how can I do this?

Upvotes: 0

Views: 2016

Answers (2)

Russell Shingleton
Russell Shingleton

Reputation: 3196

Your action should look similar to this:

public class LocatorAction extends ActionSupport {
      private Foo foo;

      public Foo getFoo() {
           return foo;
      }

      public void setFoo(Foo foo) {
           this.foo = foo;
      }
 }

and on the JSP:

 <s:property value="foo" />

or if the object has fields like address, city, state, zip, etc:

 <s:property value="foo.address" /> 
 <s:property value="foo.city" />
 <s:property value="foo.state" />    

Upvotes: 1

Jigar Joshi
Jigar Joshi

Reputation: 240948

Set the value of variable into one of the field of form which is binded with the required view and simply display it.

Upvotes: 0

Related Questions