I cannot implement the Arraylist values in the table in the JSP file

Asked

Viewed 68 times

0

I’m starting out in Java Web content and got stuck in the following situation:

I am trying to transfer the Arraylist values created inside the JSP file to the table that is inside the JSP file as well; but I cannot iterate those values into the table. I am creating the code in Eclipse because it was the IDE that I most identified with, but the teacher gave the content in Netbeans.

I don’t know if the code is wrong because the syntax in the IDE is different. In addition, the professor did not care about my doubt, perhaps because he did not know how to handle the Eclipse or because he did not want to help, and I need help to continue with the content. The code goes below:

<%@page import=java.util.ArrayList %>
<%@page import=escola.Aluno %>

<table border="">

    <tr>
        <th><b>ID</b></th>
        <th><b>Nome</b></th>
        <th><b>Série</b></th>
    </tr>

    <%
        ArrayList<Aluno> alunos = new ArrayList<Aluno>();

        alunos.add(new Aluno(1, "Hugo", "1º ano/médio"));
        alunos.add(new Aluno(2, "José", "2º ano/médio"));

        for (Aluno al : alunos) {


            out.println("<tr>");
            out.println("<td>" + al.getId() + "</td>");
            out.println("<td>" + al.getNome() + "</td>");
            out.println("<td>" + al.getSerie() + "</td>");
            out.println("</tr>");

        }
    %>

</table>

The code and values are all printed in line above the skeleton of the created table (ID, Name and Series). I own this Student class with the constructor containing the elements in this order of Arraylist creation.

  • Is there an error in your server console? I warn against using scriptlets (java code along with html) as a bad practice.

  • The problem was the absence of quotation marks on the import of Arraylist and the Student class. I just read today about this bad practice haha I think the teacher only did it this way to present the jsp, but thanks for the tip!

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.