最佳答案
我在 request
对象中设置了如下值,
String[] categoriesList=null;
categoriesList = engine.getCategoryNamesArray();
request.setAttribute("categoriesList", categoriesList );
这就是我在 jsp 页面中迭代的方式
<% if(request.getAttribute("categoriesList") != null) { %>
<c:forEach var="categoryName" items="${categoriesList}">
<li><a onclick="getCategoryIndex()" href="#">${categoryName}</a></li>
</c:forEach>
<% }%>
How do I get index of each element and pass it to JavaScript function onclick="getCategoryIndex()"
.