2013-02-09 59 views
3

我想在创建一个动态表时接受书属性,当它提供了no。要在前一页输入的书籍。 但我没有得到任何东西。如何使用count和JSTL动态创建表格ForEach

这是我的代码:

<table> 
<c:forEach begin="1" end= "${ no }" step="1" varStatus="loopCounter"> 
<tr> 
<td> 
<input type='text' name="isbn" placeholder="ISBN"> 
</td> 
<td> 
<input type="text" name="Title" placeholder="Title"> 
</td> 
<td> 
<input type="text" name="Authors" placeholder="Author"> 
</td> 
<td> 
<input type="text" name="Version" placeholder="Version"> 
</td> 
</tr> 
</c:forEach> 
</table> 

$ {}无以书我想输入数字的计数。 我是新来的。对不起,如果标题不清楚。请帮忙。

回答

4

你没有得到任何东西,因为你没有迭代你的书籍列表。此外,每次迭代只打印大量<input type="text" />。您的代码应该是这样的(假设你的书单是lstBooks和它已经初始化):

<table> 
    <!-- here should go some titles... --> 
    <tr> 
     <th>ISBN</th> 
     <th>Title</th> 
     <th>Authors</th> 
     <th>Version</th> 
    </tr> 
    <c:forEach begin="1" end= "${ no }" step="1" varStatus="loopCounter" 
     value="${lstBooks}" var="book"> 
    <tr> 
     <td> 
      <c:out value="${book.isbn}" /> 
     </td> 
     <td> 
      <c:out value="${book.title}" /> 
     </td> 
     <td> 
      <c:out value="${book.authors}" /> 
     </td> 
     <td> 
      <c:out value="${book.version}" /> 
     </td> 
    </tr> 
    </c:forEach> 
</table> 

根据意见理解你的问题后,确保${no}变量可在request.getAttribute("no")。您可以使用scriptlet(但是这是一个bad idea)或仅使用<c:out value="${no}" />来测试。

请注意,正如我所说的,变量应该通过request.getAttribute访问,请勿将其与request.getParameter混淆。

顺便说一句,你可以设置一个变量,如果你知道这可能是是这样的值:

<c:set var="no" value="10" /> 

然后你就可以访问它使用${no}来。

更多信息:JSTL Core Tag

+0

我想要输入。这就是为什么我有。实际上所有的例子都只是基于迭代的。是否有可能正常循环?例如:打印一行10次 – 2013-02-09 06:16:30

+0

你想在那里输入书中的值吗? – 2013-02-09 06:17:11

+0

是的。我想创建这种不接受用户书籍的动态表单。它将输入作为前一页的书籍的数量。对不起,没有什么信息 – 2013-02-09 06:20:52