开发者

Display String array in spring MVC

开发者 https://www.devze.com 2023-04-07 13:24 出处:网络
I am trying to display string array in JSP page. I have got a test String array in my controller set this to my registration model

I am trying to display string array in JSP page.

I have got a test String array in my controller set this to my registration model

String[] test={"ab","cb","sc","ad"};
registration.setTestArray(test);

Now I am trying to display it in jsp Its working fine if I do like this

<tr>
        <c:forEach var="arr" items="${registration.testArray}">
            <td>${arr} </td>
        </c:forEach>
    </tr>

But my problem is I want to display only some of the values from this array like 2nd and 4th index of this array.

I tried like

<tr>
        <c:forEach var="arr" items="${registration.testArray}">
            <td>${arr[2]} </td>
        </c:forEach>
    </tr>

but its throwing an erro开发者_Python百科r. This is just a test in my actual project I have long array of array from which I have to display some selected values.

I am thinking of doing this by first process my required values in controller and then display it in jsp. But I am not sure is this the best method. It would be great help if someone suggest me the better way.


It depends on how you get these "selected values". You can:

  • ${registration.testArray[2]}
  • you can loop using a specific step of the c:forEach tag
  • you can loop everything and check <c:if test="${selectedValues.contains(arrItem)}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号