Doubt with servlets of java and sql [closed]

0

In this small servlet I am entering the values in hard and I would like the hard values to have parameters so that the information can be stored since it would be on the client's side where this information is entered.

protected void doGet(HttpServletRequest req, HttpServletResponse resp)
    throws ServletException, IOException {
    InsertarPublicacion ObtenerIdRedSh= new InsertarPublicacion(pool);
    String id=ObtenerIdRedSh.procedure("Nota:De Juan Barragan") ;
    response.getOutputStream().write(id.getBytes());
}
    
asked by NymHaRI 16.08.2017 в 00:27
source

1 answer

1

You can obtain the parameters of the request object. Example:

<form method='POST' action='/EjemploServlet'>
    <label for='nombre'>Ingrese su nombre: </label>
    <!--
        Lo principal para identificar al parámetro es el atributo 'name', no el id
    -->
    <input type='text' id='nombre' name='nombre' />
</form>

Then, in your servlet, you would have this code:

@WebServlet("/EjemploServlet")
public class PruebaServlet extends HttpServlet {

    @Override
    public void doPost(HttpServletRequest req, HttpServletResponse res)
        throws IOException, ServletException {

        String nombre = req.getParameter("nombre"); //<-- Ojo, se identifica por el campo 'name' del <input>
        System.out.println(String.format("Valor de parámetro 'nombre': %s", nombre));
        //usa el valor del parámetro para lo que necesites...
    }
}
    
answered by 16.08.2017 в 04:58