pass value from a java class to a jsp

0

I would like to know how I can pass the value of a variable from a java class to a jsp.

public void ValidateUser (String user, String password, HttpServletRequest request) {

    try {

        Connection conexion=null;
        PreparedStatement pst = null;
        ResultSet rs = null;

        conexion = DriverManager.getConnection("jdbc:mysql://localhost:3306/ticketsdetrabajo", "root", "123456");
        //creamos objeto Statement

    pst=conexion.prepareStatement(sql);
    pst.setString(1, usuario);
    pst.setString(2, password);
    rs=pst.executeQuery();


    if(rs.next())
    {
        dbUsuario=rs.getString("NombreUsuarios");
        dbPass=rs.getString("Contrasena");
        if(dbUsuario.equals(usuario)&& dbPass.equals(password)) {
            HttpSession sesion = request.getSession();
            login=true;

        }       
    }else {
        System.out.print("El usuario o Contraseña introducidos son erroneos");
        login=false;

    }

I would like to pass the login variable to a jsp page to redirect to the page only if it is correctly registered:

    
asked by gulez 21.05.2018 в 13:43
source

2 answers

1

Save it in session:

sesion.setAttribute("login", login);

And then you collect it in jsp from the session scope:

<%= session.getAttribute("login") %>

Greetings.

    
answered by 21.05.2018 / 13:46
source
0

Thank you very much. More or less I already have it. The problem is when I hit the back page, I no longer take the value of the new login

    
answered by 22.05.2018 в 10:41