bob90937 bob90937 - 1 month ago 10
Java Question

how to change the scriplet to JSTL display string array

how to change the scriplet to JSTL

<%String sentenceArray[] = (String[])request.getAttribute("displaySentenceArray"); %>

<% for (int i=0; i< sentenceArray.length;i++){ %>

<p> The Result IS : <%=sentenceArray[i] %> </p>

<%} %>


I am new to JSTL

Answer

Your JSTL should look like this

    <c:forEach var="sentence" items="${requestScope.displaySentenceArray}" >
        <p> The Result IS   :<c:out value="${sentence}"></c:out></p>
    </c:forEach>

Here requestScope.displaySentenceArray will get the whole array from request.'sentence'will be a single element of array, tag will iterate the array and will print the element to JSP.

Comments