loginaction.java

来自「基于servlet/xml开发的网上书店 下载有需写web.xml配置」· Java 代码 · 共 48 行

JAVA
48
字号
package netstore.security;

import java.util.Locale;
import javax.servlet.http.*;
import javax.servlet.ServletContext;
import org.apache.struts.action.*;
import org.apache.struts.util.MessageResources;
import netstore.businessobjects.Customer;
import netstore.framework.exceptions.*;
import netstore.framework.SessionContainer;
import netstore.framework.NetstoreBaseAction;
import netstore.framework.util.IConstants;
import netstore.service.INetstoreService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
 * Implements the logic to authenticate a user for the netstore application.
 */
public class LoginAction extends NetstoreBaseAction {
  protected static Log log = LogFactory.getLog( NetstoreBaseAction.class );
  /**
   * Called by the controller when the a user attempts to login to the
   * netstore application.
   */
  public ActionForward execute( ActionMapping mapping,
                                ActionForm form,
                                HttpServletRequest request,
                                HttpServletResponse response )
  throws Exception{
    MessageResources messages=getResources(request);
    ActionMessages errors=new ActionMessages();
    // Get the user's login name and password. They should have already
    // validated by the ActionForm.
    String email = ((LoginForm)form).getEmail();
    String password = ((LoginForm)form).getPassword();

    // Obtain the ServletContext
    ServletContext context = getServlet().getServletContext();

    // Login through the security service
    INetstoreService serviceImpl = getNetstoreService();

    Customer  customer= serviceImpl.authenticate(email, password);
    SessionContainer existingContainer = getSessionContainer(request);
    existingContainer.setCustomer(customer);
    return mapping.findForward(IConstants.SUCCESS_KEY);
  }
}

⌨️ 快捷键说明

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