How to link a link to an object? Servlet

-1

I have a servlet solution, I have a form written in html, save the data in a database, I get this data and I have an html table, in this table it has the attributes of the person object, one of the values of these columns is a link, when the user clicks on this link I have to delete the person corresponding to that line, the doubt is: how do I link a person with a link? Following is an image of the table. Delete is a link to delete the person, but it is a link that does not go anywhere, merely illustrative, to help with the abstraction ...

    
asked by anonymous 26.09.2015 / 03:52

1 answer

0

Here is the code built, it is very simple, it has two JSP pages and a Servlet, here I use the DAO standard, we have the User class that represents our "user" object, the UserDAO class that makes bridge between the database and the application, finally we have the DbUtil class that creates the connection through the data entered in the db.proprerties file.  In order to use it you must use the following files in the lib directory of your web project:   jtsl.jar along with standart.jar I used the PostgreSQL database, and so I used the file postgresql-9.4-1202.jdbc4.jar if you use MySQL or another bank, just change the file (connection driver) to agree with your bank.
 The whole process works with session control and with the use of the RequestDispatcher class that is used within the single servlet of the UserController application.  First of all I would like to say that I just addressed what is necessary to get your answer with the code, interesting things like error handling, in case the "user" insert a string for the CPF I left it second hand, but that you can do with tranquility, To test the code suppose the user will type everything as expected !!
Here is the JSP page that inserts your link to delete the users:

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 <link type="text/css"
              href="css/estilo.css"rel="stylesheet" />
<title>Todos Usuários</title>
</head>
<body>
    <table border=1>
        <thead>
            <tr>
                <th>CPF</th>
                <th>Nome</th>               
                <th>Sexo</th>
                <th>Salário</th>
                <th colspan=2>Ação</th>
            </tr>
        </thead>
        <tbody>
            <c:forEach items="${users}" var="user">
                <tr>
                    <td><c:out value="${user.CPF}" /></td>
                    <td><c:out value="${user.nome}" /></td>                         
                    <td><c:out value="${user.sexo}" /></td>
                    <td><c:out value="${user.salario}" /></td>  

                    <td><a href="UserController?action=delete&CPF=<c:out value="${user.CPF}"/>">Delete</a></td>
                </tr>
            </c:forEach>
        </tbody>
    </table>
    <p><a href="UserController?action=insert">Adicionar novo  Usuário</a></p>
</body>
</html>

You can download the complete project in the GITHUB , for further analysis

    
26.09.2015 / 20:20