I want to show the data from an array using JSP.
I have three files:
index.jsp
:<%@page contentType="text/html" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>JSP Page</title> </head> <body> <h1>Hello World! </h1> <form name="Input Name Form" action="response.jsp"/> <p> Enter your name:</p> <input type="text" name="name"/> <input type="submit" value="ok" /> </form> </body> </html>
response.jsp
:<%@page contentType="text/html" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>JSP Page</title> </head> <body> <h1>Hello World!</h1> <br> <jsp:useBean id="aaa" scope="page" class="A.a" /> <jsp:setProperty name="aaa" property="name" value="<%= request.getParameter("name")%>" /> <jsp:getProperty name="aaa" property="name" /> </body> </html>
a.java
:public class a { public a () {} private String name; ArrayList() array_list = new ArrayList(); public String getName() { return name; } /** * @param name the name to set */ public void setName(String name) { this.name = name; //some magic to fill array_list with values } }
My question is:
What statement should I use in jsp to get values from array_list
in a.java
?
I know that there is statement
<c:forEach> </c:forEach>
but I am not sure how to use it.