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
That's right:
- Get data in a servlet / controller / DAO, generally outside of the JSP. Means JDBC: we create
Connection
,создаем Statement
, weзапускаем Statement
, we take awayResultSet
. - 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).
- Pass this list to JSP.
- 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
- oneYou 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
|