-2

I would like to create multiple textbox dynamically using for loop and each of textboxes must have different names so that i can get the values from those textboxes using request.getParameter('textboxName').

So how to create multiple textboxes with different names using for loop in JSP ?

Jasper de Vries
  • 19,370
  • 6
  • 64
  • 102
ALTAF
  • 41
  • 11
  • create a list of textbox names and iterate over the list while creating textboxes. – akshaya pandey Jun 07 '18 at 09:51
  • 2
    Hello there. As you are seemingly quite new on Stack Overflow I recommend you to [take the tour](https://stackoverflow.com/tour) and read the [Help Center](https://stackoverflow.com/help) in order to learn how to ask a good and well-received question. Currently you are showing no attempt to solve your problem on your own which is definitely not well-received most of the time. Show us what you have done so far and narrow your problem down to a specific point and we might be able to help you. – Ben Jun 07 '18 at 09:52

2 Answers2

0

I think something like this would work.

<body>
      <%for ( int i= 1; i <= 5; i++){ %>
         <input type="text" name ="<%= "textBox"+i %>">


      <%}%>
   </body> 

I have not checked it but it will work and will create 5 text boxes with names textBox1 , textBox2 and so on.

bit-shashank
  • 887
  • 11
  • 27
0

As you can read in the top answer on How to avoid Java code in JSP files?, the use of scriptlets in JSP is highly discouraged since the birth of taglibs (like JSTL) and EL (Expression Language) way back in 2001.

So I would advice to use JSTL (which you already used to tag your question):

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<c:forEach begin="1" end="5" var="i">
  <input type="text" name="input${i}"/>
</c:forEach>
Jasper de Vries
  • 19,370
  • 6
  • 64
  • 102