* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
*/
package com.apple.struts.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.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import com.apple.struts.MyBean;
import com.apple.struts.ShoppingCart;
import com.apple.struts.form.LoginForm;
public class LoginAction extends Action {
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
LoginForm loginForm = (LoginForm) form;// TODO Auto-generated method
// stub
String username = loginForm.getUsername();
String password = loginForm.getPassword();
MyBean bean = new MyBean();
bean.setUsername(username);
bean.setPassword(password);
ActionErrors errors = new ActionErrors();
if (bean.process()) {
HttpSession newSession = request.getSession(true);
ShoppingCart myShoppingCart = new ShoppingCart();
newSession.setAttribute("myShoppingCart", myShoppingCart);
newSession.setMaxInactiveInterval(10000);
newSession.setAttribute("loginForm", loginForm);
return (mapping.findForward("success"));
} else {
errors.add("UserAndPass",new ActionError("error.UserAndPass"));
this.saveErrors(request, errors);
return (new ActionForward(mapping.getInput()));
}
}
}
发表于 @ 2007年03月29日 20:01:00|编辑