Spring returning NULL in only one form field

0

I'm learning Java and am having a problem with a form using Spring. Until I found a similar problem here in the forum but a little different from mine.

It is a basic login page, containing only two fields, login and password. The problem is that when I submit the form, the password is filled correctly but login always comes with NULL.

Is something missing or am I making a mistake in the code?

Any comments and / or criticisms of this code are welcome, after all I am here to learn, remembering that it is just a simple code to assimilate knowledge.

Thanks in advance to anyone who can help. Many thanks!

This is my page:

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

<html>
    <body>
        <c:import url="/WEB-INF/jsp/cabecalho.jsp" />

        <h3>Efetue seu Login</h3>

        <form action="efetuaLogin" method="post">           
            Login: <input type="text" name="login" /><br/>          
            Senha: <input type="password" name="senha" /><br/>          
            <input type="submit" value="Entrar" />
        </form> 

        <br/>
        <a href="http://localhost:8180/fj21-tarefas">Home</a>
        <a href="http://localhost:8180/fj21-tarefas/listaTarefas">Listar Tarefas</a>        

        <br/>
        <c:import url="/WEB-INF/jsp/rodape.jsp" />
    </body>
</html>

Controller:

package br.com.stefanini.tarefas.controller;

import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import br.com.stefanini.tarefas.servlet.Usuario;
import br.com.stefanini.tarefas.servlet.UsuarioDao;

@Controller
public class LoginController {

    @RequestMapping("loginForm")
    public String loginForm(){
        System.out.println("Aqui");
        return "login";
    }

    @RequestMapping("efetuaLogin")
    public String efetuaLogin(Usuario usuario, HttpSession session){

        if (new UsuarioDao().existeUsuario(usuario)) {
            session.setAttribute("usuariologado", usuario);
            return "menu";
        }
        return "redirect:loginForm";
    }
}

Model:

package br.com.stefanini.tarefas.servlet;

public class Usuario {

    private String login;    
    private String senha;    

    public Usuario() {
        super();
    }

    //Getters
    public String getLogin() {
        return login;
    }

    public String getSenha() {
        return senha;
    }

    //Setters
    public void setUsuario(String login) {
        this.login = login;
    }

    public void setSenha(String senha) {
        this.senha = senha;
    }
}
    
asked by anonymous 08.04.2017 / 19:45

1 answer

0

In your Model Usuario , change the method setUsuario to setLogin

    
22.05.2017 / 20:05