Home > database >  How can I save all the data from different textboxs in an array, using JSTL?
How can I save all the data from different textboxs in an array, using JSTL?

Time:08-09

I want to recieve any number of textbox values, and save it to an array with JSTL if it's possible.

I generate all the texbox where numberAsked can be any number.

<c:if test="${param.buttonSend != null}">
        <form action="index.jsp" method="post">
                <c:forEach var = "i" begin = "1" end = "${param.numberAsked}">
                        <input type="text" name="textbox[]" >
                </c:forEach>
            <button type="submit" name="buttonSave">Save</button>
        </form>
</c:if>

Now I want to save all the textboxs in an array.

<c:if test="${param.buttonSave != null}">
    <c:set var="data" value="${request.getParameterValues(textbox)}"/>
    <c:forEach var = "item"  items="${param.data}">
        <c:out value="${item}"/>
    </c:forEach>
</c:if>

But, it doesn't work, how can I save all the data from all the generated textboxs in an array?.

CodePudding user response:

Here is a demonstration JSP.

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<form method="post">
    <c:forEach var = "i" begin = "0" end = "5">
         <input type="text" name="textbox">
    </c:forEach>
    <button type="submit" name="buttonSave">Save</button>
</form>
    <c:set var="data" value="${paramValues.textbox}"/>
    <c:forEach var = "item"  items="${data}">
        ${item}
    </c:forEach>
       
  • Related