java - 在 JSP 中访问操作 getter

标签 java jsp web-applications struts2 jsp-tags

我是 Struts 新手,我想在 JSP 中访问 Action 类中的一些值。我如何访问这些值?

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

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

这就是我正在尝试的方法。

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

最佳答案

这是我的程序 - 完美运行:

 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 逻辑

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

关于java - 在 JSP 中访问操作 getter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15169846/

相关文章:

Java - Servlet,在整个项目中携带登录信息( session bean)

css - jsp 页面作为 Tomcat 上的 css 文件

java - 从servlet发送数据到jsp

java - 我什么时候会使用 ant 进行 Java Web 开发?

java - android studio "earthquake app"中的 gradle 同步问题

java - 这是否意味着在没有 JavaScript 的情况下在 jsp 中显示 JSON 字符串?

html - 是否可以将div的滚动条居中并溢出:scroll

用于网络脚本的 Python

java - KeyListener 不适用于文本框?

java - JSP 读取器/写入器无法正常工作