简体   繁体   中英

For iterator is not being recognized in struts 2 execute method?

I have this execute method action for struts2 in my program, it validates a login form in my webpage, checking an arraylist called listaUsuarios where my usuarioBean objects are being stored, to find if the username and the password are equal in those attributes

public String executeLogin() {

    String go = ERROR;

    for (Usuario u : s.getListaUsuarios()) {
        if (usuarioBean.getNombreUsuario().equals(u.getNombreUsuario())) {
            if (usuarioBean.getContrasenna().equals(u.getContrasenna())) {
                if (u instanceof Administrador) {
                   go="admin";
                   break;
                }
                if (u instanceof Cliente) {
                   go="cliente";
                   break;
                }
                if (u instanceof Proveedor) {
                   go="proveedor"; 
                   break;
                }
            }

        }
    }

    return go;
}

This doesn't work, it doesn't validate anything but if I put in my login form, this hardcoded method, it works, so I'm not sure what is happening

   public String executeLogin() {

    String go = ERROR;

    if (usuarioBean.getNombreUsuario().equals("jean182")) {
        if (usuarioBean.getContrasenna().equals("123")) {
            go = "admin";
        }
    }
     return go;
}

Did you print the string you read from the form? The problem could be that those are not equals to the ones stored (spaces at the end, upper case / lower case)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM