I have two Lists. The first list ( numberList) contains two integer elements: [1] and [5] The second list (stringList) contains ten String. I'd like to use EL to display the first and the fifth element of the second list using the number 1 and 5 contained in the first one. I'd like to write something like this using EL:
开发者_开发技巧<c:out value="${stringList[numberList[0]]}" />
<c:out value="${stringList[numberList[1]]}" />
Is it possible using EL?
It's perfectly valid.
Assuming the following servlet
List<Integer> numberList = Arrays.asList(0, 4);
request.setAttribute("numberList", numberList);
List<String> stringList = Arrays.asList("one", "two", "three", "four", "five");
request.setAttribute("stringList", stringList);
request.getRequestDispatcher("/WEB-INF/page.jsp").forward(request, response);
and the following JSP
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
...
<c:out value="${stringList[numberList[0]]}" />
<c:out value="${stringList[numberList[1]]}" />
you should see this in your webbrowser when invoking the servlet
one five
精彩评论