Search code examples
javajspweb-applicationsstruts2jsp-tags

Access action getters in the JSP


I am new to Struts and I have some values in the Action class that I would like to access in the JSP. How can I access these values?

public static String[] getSoldItemsColNames() {
    return SellerHistory.soldItemsColNames;
}

public ItemType[] getActiveItems() {
    return sellerHistory.getActiveItems();
}

This is how I am trying.

<s:iterator value="soldItemsColNames" status="soldItemsColNames" var="element"> 
<th><s:property value="%{#element}" /></th> 
</s:iterator> 

Solution

  • Here is my program - works perfectly:

     Action class : 
     static Account[] account=new Account[1];
     static String[] arrayofStrings={"1","2","4"};
     {
        Account a=new Account();
        a.setName(arrayofStrings);
        account[0]=a;
    
     } 
    
     //..getters and setters , execute()
    
      public String[] getArrayofStrings() {
        return this.account[0].getName();//Just like yours
      }
    

    JSP Logic

      <s:iterator value="arrayofStrings" status="true" var="element">
      <p><s:property value="%{#element}" /></p>
      </s:iterator>