bob90937 bob90937 - 8 months ago 50
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


Your JSTL should look like this

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

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.