各位高手帮看一下,本人看了很久都看不明白

解决方案 »

  1.   

    // Extract attributes we will need
    Locale locale = getLocale(request);                
    MessageResources messages = getResources(request); ---这部分好象是去本地资源的吧,用于国际化版本的通用。
    User user = null; // Validate the request parameters specified by the user
    ActionErrors errors = new ActionErrors();
    String username = (String)                                  ???(String)PropertyUtils.getSimpleProperty(form, "username") 这句好像是取值,有点不太了解?特别是这个PropertyUtils.getSimpleProperty不懂是什么意思?
                PropertyUtils.getSimpleProperty(form, "username");
            String password = (String)
                PropertyUtils.getSimpleProperty(form, "password");
    UserDatabase database = (UserDatabase)
      servlet.getServletContext().getAttribute(Constants.DATABASE_KEY); ---Cnstants.DATABASE_KEY是个常量,查一下struts的api,有个Constants类的。
    if (database == null)
                errors.add(ActionErrors.GLOBAL_ERROR,
                           new ActionError("error.database.missing"));       ---保存错误消息。 else {
        user = getUser(database, username);
        if ((user != null) && !user.getPassword().equals(password))
    user = null;
        if (user == null)
                    errors.add(ActionErrors.GLOBAL_ERROR,
                               new ActionError("error.password.mismatch"));
    } // Report any errors we have discovered back to the original form
    if (!errors.isEmpty()) {                        --非空说明上面有了错误,下面就不是空了,就要处理错误
        saveErrors(request, errors);
                return (mapping.getInputForward());
    } // Save our logged-in user in the session
    HttpSession session = request.getSession();        --取得当前用户Session
    session.setAttribute(Constants.USER_KEY, user);    --设Session属性,Constants.USER_KEY就是一个常量字符串.
            if (log.isDebugEnabled()) {                       ---可以在配置文件中定义Debug是否打开,如果打开的话,就打印log
                log.debug("LogonAction: User '" + user.getUsername() +
                          "' logged on in session " + session.getId());
            }