Hello, tell me, how is it CORRECT to make a table output from a database to a JSP page based on JDBC (without adding logic to a JSP )?

    1 answer 1

    That's right:

    1. Get data in a servlet / controller / DAO, generally outside of the JSP. Means JDBC: we create Connection , создаем Statement , we запускаем Statement , we take away ResultSet .
    2. We transform the data into a more / less adequate representation, for example, a list of class instances that wraps this data (the so-called Value Object, Data Transfer Object).
    3. Pass this list to JSP.
    4. In JSP we go over the list and form a nameplate.

    .

     <table> <c:forEach var="person" items="${people.people}"> <tr> <td>${person.name}</td> <td>${person.age}</td> <td>${person.height}</td> </tr> </c:forEach> </table> 
    • Thanks, but the problem is to get this very <code> "items" </ code> - maxus
    • And what exactly is the problem? - Nofate
    • get access to jsp table - maxus
    • one
      You yourself must transfer the collection from the controller to the JSP. If you call JSP from a simple servlet forward, it will look something like this: request.setAttribute("items", items); . Well, then use them in JSP. Look through [Student Human Resources] [1] [1]: java-course.ru/students/students.php?name=part9 - Nofate
    • Thanks, come in handy! - maxus