Answer the question
In order to leave comments, you need to log in
Can't get list from server?
Can't get ArrayList from server.
Server:
public class Servlet extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String val = request.getParameter("val");
Double num = Double.parseDouble(val);
if (num > 0 && num <9 ){
List<String> listStrings = new ArrayList<String>();
listStrings.add("One");
listStrings.add("Two");
listStrings.add("Three");
request.setAttribute("listStrings",listStrings);
} else {
}
request.getRequestDispatcher("index.jsp").forward(request,response);
...
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
myFunction(this);
}
};
xhttp.open("POST", 'Servlet', true);
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhttp.send("val="+ val);
function myFunction(???) {
???
document.getElementById("demo").innerHTML = ???;
}
...
$(document).on("click", "#somebutton", function() {
$.get("someservlet", function(responseXml) {
$("#somediv").html($(responseXml).find("data").html()); });});
<table>
<c:forEach items="${listStrings}" var="product">
<tr>
<td>${product}</td>
<td><c:out value="${product}" /></td>
</tr>
</c:forEach>
</table>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question