I want to create a dynamic table accepting book attributes when it has provided the no. of books to be entered on the previous page.
But I am not getting anything.
This is my code:
<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>
${no} is the count of number of books I want to enter.
I am new here. Sorry if the title is not clear. Please help.
You’re not getting anything because you’re not iterating your list of books. Also, you’re only printing lots of
<input type="text" />on each iteration. Your code should look like this (assuming that your list of books islstBooksand it’s already initialized):After understanding your problem based on comments, make sure the
${no}variable is available atrequest.getAttribute("no"). You can test this using a scriptlet (but this is a bad idea) or just using<c:out value="${no}" />.Note that as I’ve said, the variable should be accesible through
request.getAttribute, do not confuse it withrequest.getParameter.By the way, you can set a variable if you know which could be it’s value like this:
And then you can access to it using
${no}.More info: JSTL Core Tag