我下不到源代码,楼上的可有源代码,发一个给我吧:[email protected] 先谢谢了

解决方案 »

  1.   

    兄弟,我也在看Struts in Action , 也看到这里,以下是书上的一段话:
    “我们将用户添加到UserDirectory 中③,并返回与success 对应的ActionForward 。UserDirectory 是一个helper 类,它记录usernames 和passwords 到一个标准的属性文件之中。否则,返回与failure 对应的ActionForward 。当我们在下一步创建struts-config 文件时,我们将标识代表success和failure的ActionForward对象。”我旁边的人也说,代码有问题,不能调试成功!
      

  2.   

    现在看明白了,UserDirectory是业务逻辑层的类,在书中他为了简化就在控制层的类中直接使用了他,从书上看这是一个验证用户名和密码合法性的,如果使用了数据库那这个类应该是直接跟数据库打交道的类了。
      

  3.   

    在ActionForm中的代码:
    public ActionErrors validate(ActionMapping mapping,HttpServletRequest request) {
    ActionErrors errors = new ActionErrors();
    if ((username == null) || (username.length() < 1))
    errors.add ("username",new ActionError("error.username.required"));
    if ((password == null) || (password.length() < 1))
    errors.add("password",new ActionError("error.password.required"));
    return errors;
    }
    这段代码应该是用来做初始校验,如果用户名、密码没有输入或者输入的长度不合法,程序都会在这里把错误给拦截下来并反馈回登录页面,如果通过了,则控制器进一步把任务交给Action做,在Action中的校验应该是验证用户输入的用户名和密码是否是系统的合法用户。就像上面刚提到的。这样理解不知道是否正确,请指教。