📄 loginaction.java
字号:
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
//获取servlet上下文
ServletContext context = getServlet().getServletContext();
// Login through the security service
INetstoreService serviceImpl = getNetstoreService();
//这里可能会抛出异常
//抛出异常后,struts配置文件中会有gloal捕获,然后返回给登陆页面
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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -