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

📄 loginaction.java

📁 模仿当当网基于struts+hierbernate与mysql的商务网站。
💻 JAVA
字号:
package org.whatisjava.dang.action;import javax.servlet.http.Cookie;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import javax.servlet.http.HttpSession;import org.apache.log4j.Logger;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 org.apache.struts.action.ActionMessage;import org.apache.struts.action.ActionMessages;import org.whatisjava.dang.domain.User;import org.whatisjava.dang.form.UserLoginForm;import org.whatisjava.dang.service.AuthorizeService;public class LoginAction extends Action {	Logger logger = Logger.getLogger(this.getClass());	public ActionForward execute(ActionMapping mapping, ActionForm form,			HttpServletRequest request, HttpServletResponse response) {		UserLoginForm lf = (UserLoginForm) form;		System.out.println(lf);		String email = lf.getEmail();		String pwd = lf.getPassword();		logger.debug(email + pwd);		AuthorizeService service = new AuthorizeService();		User user = service.validateUser(email, pwd);		logger.debug(user);		HttpSession session = request.getSession();		if (user != null) {			logger.debug(user.isEmailVerified());			if (user.isEmailVerified()) {				Cookie cookie = new Cookie("dang.user.id", String.valueOf(user						.getId()));				cookie.setMaxAge(60*60*24*30);				cookie.setPath(request.getContextPath());				response.addCookie(cookie);				session.setAttribute("user", user);				return mapping.findForward("success");			} else {				Cookie cookie = new Cookie("dang.user.tmp", user.getId()						.toString());				cookie.setMaxAge(60*60*24);				cookie.setPath(request.getContextPath());				response.addCookie(cookie);				return mapping.findForward("unverified");			}		}		ActionMessages messages=new ActionMessages();		messages.add("password", new ActionMessage("error.login"));		this.saveErrors(request, messages);		return mapping.getInputForward();	}}

⌨️ 快捷键说明

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