【问题标题】:struts 2.0 iterator Tags prbmstruts 2.0 迭代器标签 prbm
【发布时间】:2012-06-21 21:09:02
【问题描述】:

我有一个 jsp 和一个 struts 2.0 动作类。我在我的动作类中设置了一个列表,我将在我的 jsp 中使用它。

模型类是:

public class Student {
    int stdid;
    String stdName;
    String stdroll;
    Address stdAddress;
}

public class Address {
    String houseNo;
    String street;
    String area;
    String state;
    String country;
    String pin;

}

public class IteratorKFCAction extends ActionSupport{

    private List<Student> studentList;

    public List<Student> getStudentList() {
        return studentList;
    }

    public void setStudentList(List<Student> studentList) {
        this.studentList = studentList;
    }

    public String execute() {

        studentList = new ArrayList<Student>();
        studentList.add(std1);
        studentList.add(std4);
        studentList.add(std3);
        studentList.add(std2);
        return SUCCESS;
    }
}

现在,我想在我的 jsp 上显示每个学生的地址。 我想用特定的密码显示学生的地址。有人能帮我吗。

【问题讨论】:

    标签: java struts2 struts


    【解决方案1】:

    你能不能展示一下你到目前为止所做的尝试以及你得到了什么结果。这些结果与您正在寻找的结果有何不同?

    【讨论】:

      【解决方案2】:

      您可以尝试使用struts标签来迭代JSP中的列表。

      将struts标签库导入JSP文件。

      <%@taglib uri="/struts-tags" prefix="s"%>
      

      现在迭代请求范围内可用的列表。

      <s:iterator value="#studentList" var="student">
         <label><s:property value="%{#student.stdAddress.houseNo}"/></label><br>
         <label><s:property value="%{#student.stdAddress.street}"/></label><br>
         <label><s:property value="%{#student.stdAddress.area}"/></label><br>
         <label><s:property value="%{#student.stdAddress.country}"/></label><br>
         <label><s:property value="%{#student.stdAddress.pin}"/></label><br>
      </s:iterator>
      

      还要确保您在 Student 和 Address 类中的字段具有匹配的 getter/setter 方法。

      【讨论】:

        猜你喜欢
        • 2014-10-27
        • 1970-01-01
        • 2013-07-19
        • 1970-01-01
        • 2013-01-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多