2012-09-07 127 views
3

当前正在从一个JSP中的Servlet接收Map对象的ArrayList的项目。它的工作方式是当页面被拉起时,通过jquery向一个Servlet发送一个AJAX调用,该Servlet将发送带有必要List of Maps的响应。我遇到的问题是页面加载后我试图建立一个基于Map对象中的值的表。我的代码似乎正在工作(有点)。当我用萤火虫查看XHR响应时,我可以看到正确的标签在整个页面中都有(如tr和td标签)。当我尝试在浏览器中查看页面并使用“查看源代码”时,将在forEach循环内创建的HTML不存在,只有手动创建的HTML是。JSTL嵌套的foreach循环不打印

<table> 
      <tr> 
       <th>Home</th> 
       <th>Away</th> 
      </tr> 
      <c:forEach var="currentTeam" items="${GamesList}"> 
       <tr id="game"> 
       <c:forEach var="currentGame" items="${currentTeam}"> 
        <c:if test="${currentGame.key eq 'Home' }"> 
         <td>${currentGame.value}</td> 
        </c:if> 
        <c:if test="${currentGame.key eq 'Visitor' }"> 
         <td>${currentGame.value }</td> 
        </c:if> 
       </c:forEach> 
       </tr> 
      </c:forEach> 
     </table> 

是我正在使用的当前代码。它本身被封装在一个div标签中。不知道它是否有帮助,但只有当用户单击按钮打开Jquery弹出窗口时才会显示此div。任何帮助,将不胜感激。

在Firebug查看的XHR响应看起来像这样

   <tr><td>New York Giants</td><td>Dallas Cowboys</td></tr> 
       <tr><td>Chicago Bears</td><td>Indianapolis Colts</td></tr> 
       <tr><td>Minneosta Vikings</td><td>Jacksonville Jaguars</td></tr> 
       <tr><td>New York Jets</td><td>Buffalo Bills</td></tr> 
       <tr><td>Houston Texans</td><td>Miami Dolphins</td></tr> 
       <tr><td>Tennessee Titans</td><td>New England Patriots</td></tr> 
       <tr><td>Detroit Lions</td><td>St. Louis Rams</td></tr> 
       <tr><td>New Orleans Saints</td><td>Washington Redskins</td></tr> 
       <tr><td>Cleveland Browns</td><td>Philadelphia Eagles</td></tr> 
       <tr><td>Kansas City Chiefs</td><td>Atlanta Falcons</td></tr> 
       <tr><td>Green Bay Packers</td><td>San Francisco 49ers</td></tr> 
       <tr><td>Arizona Cardinals</td><td>Seattle Seahawks</td></tr> 
       <tr><td>Tampa Bay Buccaneers</td><td>Carolina Panthers</td></tr> 

切割的简洁。而查看源代码如下所示:

   <table> 
      <tr> 
       <th>Home</th> 
       <th>Away</th> 
      </tr> 
+0

是否有您使用当前的代码? –

+0

输出是什么? 'currentGame.value'的价值是什么? – alfasin

+0

我正在使用的当前代码列在上面。 currentGame.value仅在Firebug中查看的XHR响应中打印出适当的团队名称。当我查看其他地方(查看源代码)时,没有输出。 – djdgel

回答

0

打印列表中的Servlet,并设置结果一个div内容如下

$("button").click(function(){ 
    $.ajax({url: "\ServletCall", success: function(result){ 
     $("#div1").html(result); 
    }}); 
}); 

<table> 
      <tr> 
       <th>Home</th> 
       <th>Away</th> 
      </tr> 
<div id="div1"></div> 
</table>