Alex Dowining
Alex Dowining

Reputation: 970

print a list of names in jsp

I'm trying to print out a list of names and i want to be the one down to another I'm trying this code:

       <tr>
               <td> Names: </td>

           <td>
               <c:forEach items="${names}" var="allnames">                   
                   <c:out value="${allnames} " ></c:out>                           
               </c:forEach>
            </td>

      </tr>

But it print the one next to the other. What should i change?

P.S: the result now is: Names: nick george john and i want to be :

         Names: nick
                george
                john

Upvotes: 0

Views: 814

Answers (5)

JOHND
JOHND

Reputation: 2767

Use tag

Names:

           <td>
               <c:forEach items="${names}" var="allnames">  
                   <br/>                 
                   <c:out value="${allnames} " ></c:out>                           
               </c:forEach>
            </td>

      </tr>

Upvotes: 4

Addicted
Addicted

Reputation: 1704

<td>
   <tr> Names: </tr>
   <tr>
      <c:forEach items="${names}" var="allnames">                   
          <c:out value="${allnames} " ></c:out>                           
      </c:forEach>
   </tr>
</td>

Upvotes: 0

Japan Trivedi
Japan Trivedi

Reputation: 4483

You should use the <br/> tag as suggested by @JOHND

Upvotes: 1

Ravinder Reddy
Ravinder Reddy

Reputation: 24002

Add <br/> next to <c:out>:

<c:out value="${allnames} " ></c:out> <br/>

Upvotes: 1

StepTNT
StepTNT

Reputation: 3967

Adding a <br/> after each name will print a new line

<tr>
           <td> Names: </td>

       <td>
           <c:forEach items="${names}" var="allnames">                   
               <c:out value="${allnames} " ></c:out>                           
               <br/>
           </c:forEach>               
        </td>

  </tr>

or you can include the <td> tags in your forEach (I'm not quite sure that this will work!)

Upvotes: 2

Related Questions