简体   繁体   English

对于在struts 2中不能识别迭代器的execute方法?

[英]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 我的程序中有针对struts2的执行方法操作,它验证我网页中的登录表单,检查存储我的usuarioBean对象的数组listaUsuarios,以确定用户名和密码在这些属性中是否相等

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) 问题可能是那些与存储的不相等(末尾的空格,大写/小写)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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