Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/395.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java JSTL打印嵌套对象_Java_Jsp_Map_Jstl - Fatal编程技术网

Java JSTL打印嵌套对象

Java JSTL打印嵌套对象,java,jsp,map,jstl,Java,Jsp,Map,Jstl,如何在JSP页面的映射中打印嵌套对象/属性的值 <c:foreach items="${survey}" var="survey"> <c:out value="${survey.value}" /> </c:foreach> 假设Survey有一个名为Questions的属性(这是另一个对象),我想打印这些问题(Survey.Questions.getId()或Survey.Questions.getTitle()),foreach语句的外

如何在JSP页面的映射中打印嵌套对象/属性的值

<c:foreach items="${survey}" var="survey">

    <c:out value="${survey.value}" />

</c:foreach>

假设Survey有一个名为Questions的属性(这是另一个对象),我想打印这些问题(Survey.Questions.getId()或Survey.Questions.getTitle()),foreach语句的外观如何


编辑:测量是地图而不是集合

如果嵌套特性是单个对象实例,则直接引用它,如:

<c:forEach var="surveyItem" items="${surveys}">
    ${surveyItem.title} <!-- You can use the c:out if you really want to -->
</c:forEach>
这将打印每个
问题
的标题,假设您有一个
调查
对象绑定到
调查
属性,并且
调查
对象有一组
问题
对象作为字段(使用适当的getter方法,即
getQuestions()

也可以有嵌套循环,如:

<c:forEach var="surveyItem" items="${surveys}">
    ${surveyItem.title}
    <c:forEach var="question" items="${surveyItem.questions}">
        ${question.title} 
    </c:forEach>
</c:forEach>

如果嵌套属性是单个对象实例,则直接引用它,如:

<c:forEach var="surveyItem" items="${surveys}">
    ${surveyItem.title} <!-- You can use the c:out if you really want to -->
</c:forEach>
这将打印每个
问题
的标题,假设您有一个
调查
对象绑定到
调查
属性,并且
调查
对象有一组
问题
对象作为字段(使用适当的getter方法,即
getQuestions()

也可以有嵌套循环,如:

<c:forEach var="surveyItem" items="${surveys}">
    ${surveyItem.title}
    <c:forEach var="question" items="${surveyItem.questions}">
        ${question.title} 
    </c:forEach>
</c:forEach>

基本上,如果您的调查是另一个集合对象,您需要在循环中迭代两次。比如说,

<c:foreach items="${survey}" var="survey">

    <c:out value="${survey.value}" />

    <c:foreach items="${survey.Question" var="question">
      $<c:question.item> or $<c:question.title>
     </c:foreach>
</c:foreach>

美元或$

基本上,如果您进行调查,您需要在循环中迭代两次。问题是另一个集合对象。比如说,

<c:foreach items="${survey}" var="survey">

    <c:out value="${survey.value}" />

    <c:foreach items="${survey.Question" var="question">
      $<c:question.item> or $<c:question.title>
     </c:foreach>
</c:foreach>

美元或$

请重新表述您的问题。“调查”是一个列表吗,地图?请重新表述你的问题。“调查”是一个列表吗,地图?如果调查是一个地图,这会发生什么变化?如果调查是一个地图,这会发生什么变化?