use of dao.PersonDao in project ConsoElectric by anakkarsara.
the class DeletePerson method doPost.
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
EntityManagerFactory factory = Persistence.createEntityManagerFactory("dev");
EntityManager manager = factory.createEntityManager();
EntityTransaction tx = manager.getTransaction();
tx.begin();
response.setContentType("text/html");
PrintWriter out = response.getWriter();
PersonDao pd = new PersonDao();
pd.deleteById(Long.parseLong(request.getParameter("personToDelete")));
tx.commit();
out.println("<h2><a href=\"index.html\">Retour page d'acueil</a></h2>");
out.println("<table border = 2 cellpadding = \"10\" cellspacing = \"10\" align= \"center\"> <tr> <th>Prenom</th> <th>Nom</th> <th>Email</th> ");
DAO test = new DAO(manager);
for (Person next : test.listPersons()) {
out.println(" <tr> <td>" + next.getFirstName() + "</td> <td>" + next.getFamilyName() + "</td> <td>" + next.getMail() + "</td> </tr> ");
}
out.println("</table> ");
manager.close();
}
Aggregations