开发者

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 ca开发者_开发技巧n I do this?


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" />    


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜