0
I am trying to make my JSP (index.jsp) execute a condition (if) with taglib, to decide which menu it will import, depending on an attribute (Boolean)) that is in the model (user.java).
I have already performed the debug to check if the +validate method is pulling the correct information from the database. It is working normal.
But the problem is passing it on to JSP, so she can take the test.
The test I’m trying to do is simple:
<c:if test ="${usuario.permissao == true}">
<c:import url="MenuAdmin.jsp"/>
</c:if>
This is my command code, where I perform login validation. (I don’t know if I am passing correctly to JSP.)
public class FazerLogin implements Command {
@Override
public void executar(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String login = request.getParameter("username");
String senha = request.getParameter("password");
Usuario usuario = new Usuario();
usuario.setUsuario(login);
usuario.setSenha(senha);
UsuarioService service = new UsuarioService();
if(service.validar(usuario)){
HttpSession session = request.getSession();
session.setAttribute("usuarioLogado", usuario.getUsuario());
System.out.println("Logou "+ usuario.getUsuario());
} else {
System.out.println("Não logou "+ usuario.getUsuario());
throw new ServletException("Usuario/Senha inválidos");
}
request.setAttribute("usuario", usuario);
response.sendRedirect("Index.jsp");
}}
When I do the test to check if {user.permissao == false}, it returns true. But strange that the method in debug, shows that the permission is true.
when you do
request.setAttribute("usuario", usuario);
you didn’t want to dorequest.setAttribute("usuario", usuario.getUsuario());
?– Erick Maia
But the user is already
– Kennedy Anderson
So, this new user only has login and password (at least that’s what you could see in this code) where you are putting the permission ?
– Erick Maia
Inside the validate method
– Kennedy Anderson
Try { Connection Conn = Connectionfactory.obtemConexation(); Try (Preparedstatement stm = Conn.prepareStatement(sqlSelect);) { stm.setString(1, usuario.getUsuario(); stm.setString(2, usuario.getSenha(); stm.execute(); Try (Resultset rs = stm.executeQuery();).
– Kennedy Anderson