如何在我的jsp中的bean中遍历对象属性 [英] How to Iterate through object property inside a bean in my jsp

查看:80
本文介绍了如何在我的jsp中的bean中遍历对象属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有以下属性的商品列表:

I have a list products with these attributes :

  • 标识符
  • 颜色
  • 大小
  • 供应商

供应商属性是具有以下属性的对象:

Supplier attribute is an object that has these attributes :

  • 名称
  • 电话

对于我列表中的每个产品,我想显示标识符&供应商名称.我如何用struts/jstl做到这一点?

For each product in my list, i'd like to display the identifier & the supplier name. How can i do this with struts / jstl ?

这是我正在尝试的没有成功的事情:

Here is what i'm trying with no success :

<s:iterator value="products">
    <tr>
        <td><s:property value="identifiant"/></td>
        <td><s:property value="supplier.name"</td>
    </tr>
</s:iterator>

推荐答案

每个属性都应该有吸气剂.如果productsAction类的属性,则它应该具有

There should be getters for each attribute. If the products is the property of the Action class then it should have

//default constructor

public List<Product> getPoducts(){...} //getter

Product类中

//default constructor

public String getIdentifier(){...} //getter
public String getColor(){...} //getter
public String getPhone(){...} //getter
public String getSupplier(){...} //getter

Supplier类中

//default constructor

public String getName(){...} //getter
public String getPhone(){...} //getter

在JSP中

<s:iterator value="products">
    <tr>
        <td><s:property value="identifier"/></td>
        <td><s:property value="supplier.name"/></td>
    </tr>
</s:iterator>

这篇关于如何在我的jsp中的bean中遍历对象属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆