Home > Enterprise >  Display the array on the page as an HTML table. Use output scriptlet
Display the array on the page as an HTML table. Use output scriptlet

Time:11-23

java Create an array with the following content: 1 2 3 4 5 6 7 8 9 Display the array on the page as an HTML table.

I did this like this:

<%
  int [][] Array = {{1,2,3}, {4,5,6}, {7,8,9}};
  for (int i = 0; i < a.length; i  ) {
    for (int j = 0; j < a[i].length; j  )
      Array <%=Array[i][j]%>
  }
%>

but it doesn't work

CodePudding user response:

For a JSP scriptlet (using <% %>) you must print your output. With Java this is through out.println() since out is provided in the scriptlet context.

Try the following JSP:

<%
int [][] arr = {{1,2,3}, {4,5,6}, {7,8,9}};
out.println("<table>");
for (int[] row : arr) {
    out.println("<tr>");
    for (int val : row) {
        out.println("<td>"   val   "</td>");
    }
    out.println("</tr>");
}
out.println("</table>");
%>

If this works for you then please accept this as the answer.

  • Related