📄 loginaction.java
字号:
/*
* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
*/
package com.laoniu.web.action;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import com.laoniu.service.ICustomerService;
import com.laoniu.bean.Customer;
import com.laoniu.common.BeanFactory;
import com.laoniu.common.exception.CustomerServiceException;
import com.laoniu.web.form.LoginForm;
/**
* MyEclipse Struts
* Creation date: 04-26-2008
*
* XDoclet definition:
* @struts.action path="/login" name="loginForm" input="/login.jsp" scope="request" validate="true"
* @struts.action-forward name="falture" path="/login.jsp"
* @struts.action-forward name="success" path="/listBookStore.jsp"
*/
public class LoginAction extends Action {
/*
* Generated Methods
*/
/**
* Method execute
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
*/
/**
* 1.标识用户已经成功登录
* 2.放到Session作用域中,一边其他系统资源访问Customer。
*
* */
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
LoginForm loginForm = (LoginForm) form;
String name=(String)loginForm.getUser();
String password=(String)loginForm.getPassword();
ICustomerService cs=(ICustomerService)BeanFactory.getBean(BeanFactory.CUSTOMERSERVICE);
Customer customer=null;
String choose=request.getParameter("choose");
try {
customer=cs.login(name,password);
if("1".equals(choose))
{
if("laoniu".equals(name)&& "123456".equals(password))
return mapping.findForward("manager");
}
HttpSession session=request.getSession();
session.setAttribute("customer", customer);
return mapping.findForward("success");
} catch (CustomerServiceException e) {
request.setAttribute("error",e.getMessage());
return mapping.findForward("falture");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -