我想在提供no时创建一个接受book属性的动态表.在上一页输入的书籍.但我没有得到任何东西.
这是我的代码:
<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>
Run Code Online (Sandbox Code Playgroud)
$ {no}是我想要输入的图书数量.我是新来的.对不起,如果标题不清楚.请帮忙.
你没有得到任何东西,因为你没有迭代你的书籍清单.此外,您只需<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>
Run Code Online (Sandbox Code Playgroud)
在根据注释理解您的问题后,请确保该${no}变量可用于request.getAttribute("no").您可以使用scriptlet进行测试(但这不是一个好主意)或只是使用<c:out value="${no}" />.
请注意,正如我所说,变量应该是可访问的request.getAttribute,不要混淆它request.getParameter.
顺便说一句,你可以设置一个变量,如果你知道它的值是这样的:
<c:set var="no" value="10" />
Run Code Online (Sandbox Code Playgroud)
然后你可以使用它来访问它${no}.
更多信息:JSTL核心标签