⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 loginaction.java

📁 《基于Eclipse的开源框架技术与实战》[第5章]随书源码
💻 JAVA
字号:
package com.free.struts.storefront.security;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.free.struts.storefront.customer.view.UserView;
import com.free.struts.storefront.framework.StorefrontBaseAction;
import com.free.struts.storefront.framework.UserContainer;
import com.free.struts.storefront.framework.util.IConstants;
import com.free.struts.storefront.service.IStorefrontService;
import com.free.struts.storefront.service.IStorefrontServiceFactory;

/**
 * <p>Title: Eclipse Plugin Development</p>
 * <p>Description: Free download</p>
 * <p>Copyright: Copyright (c) 2006</p>
 * <p>Company: Free</p>
 * @author gan.shu.man
 * @version 1.0
 */

public class LoginAction extends StorefrontBaseAction {
  protected static Log log = LogFactory.getLog( StorefrontBaseAction.class );
  /**
   * Called by the controller when the a user attempts to login to the
   * storefront application.
   */
  public ActionForward execute( ActionMapping mapping,
                                ActionForm form,
                                HttpServletRequest request,
                                HttpServletResponse response )
  throws Exception{

    //获昨Email(即用户名)和密码
    String email = ((LoginForm)form).getEmail();
    String password = ((LoginForm)form).getPassword();

    //获得IStorefrontService对象StorefrontDebugServiceImpl
    IStorefrontService service = getStorefrontService();

    //通过StorefrontDebugServiceImpl验证用户的有效性
    UserView userView = service.authenticate(email, password);

    //第一次登录,把用户对象UserContainer保存到HttpSession中
    UserContainer existingContainer = getUserContainer(request);
    existingContainer.setUserView(userView);
    return mapping.findForward(IConstants.SUCCESS_KEY);
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -