This is my ajax code and jstl code. I get the request attribute passed by the controller. The request was printed using "System.out.println("im here1: "+value);", but the value are not seen on the page.
$.ajax({
type: 'post',
url: '<%=formActionURL%>',
data: data,
success: function () {
console.log('succ');
<%
ArrayList<?> msgArray = (ArrayList<?>) request.getAttribute("msgList");
int index = 0;
for (Object value : msgArray) {
System.out.println("im here1: "+value);
index++;
}
request.setAttribute("msgArray", msgArray);
%>
}
});
JSTL CODE:
<c:forEach var="msgArrays" items="${msgArray}">
<p><c:out value="${msgArrays}" />
</p>
</c:forEach>
But when I use static values, it is getting printed on the page but was loaded on load of the document:
ArrayList<String> msgArray = new ArrayList<String>();
msgArray.add("pink");
msgArray.add("bubble");
int index = 0;
for (String value : msgArray) {
System.out.println("im here1: "+value);
index++;
}
request.setAttribute("msgArray", msgArray);
Can you advise me on the possible problems? I am using form submit before but it is refreshing the whole page that is why I am using ajax call. Form submit is working fine, it is just refreshing my whole page, if you can also suggest ways on not submitting the whole page, it will be great.