日期:2014-05-17 浏览次数:20740 次
public @Getter @Setter class AccountAction extends ActionSupport implements ModelDriven<Person> { private Person person=new Person(); private final String ERROR404="error404"; private final String FORMAL="formal"; private final String INDEX="index"; // 用于上一个链接 private String previousHref=ServletActionContext.getRequest().getHeader("Referer"); @Resource(name="userManagerImp") private UserManager userManger; // 登录 public String login(){ if(isUserAlreadyLogin(ServletActionContext.getRequest())) return INDEX; if(userManger.findUserByEmailAndPassword(person.getEmail(), person.getPassword())==null){ System.out.println("登录失败"+person.getEmail()+person.getPassword()); return FORMAL; } if( previousHref!= null) return SUCCESS; storeEmailAtCookieWithSession(person.getEmail()); System.out.println("登录成功"); return INDEX; } /**再次判断用户注册是否出错 * */ private boolean isWrongWithPerson(){ return person.getEmail()==null||person.getPassword().equals("")||person.getName().equals("")|| userManger.checkUserExistByEmail(person.getEmail()); } @Override public Person getModel() { return person; } }
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@taglib prefix="s" uri="/struts-tags"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>注册questionvsanswer</title> </head> <body> <s:form action="login" method="post"> <label>邮箱</label> <input id="email" name="email" type="text" maxlength="60" tabindex="1" value="" /> <br /> <label>密码</label> <input id="password" name="password" type="password" maxlength="60" tabindex="1" value="" /> <br /> <button type="submit">登录</button> </s:form> <s:include value="copyright.jsp"></s:include> </body> </html>
private long id; private String name; private String email; private String password; private String description; getter setter