日期:2014-05-17  浏览次数:20740 次

为什么我实现ModelDriven得到的是空值哦,奇怪?
AccountAction.java
Java code

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;
    }
    
    
}





login.jsp

HTML code

<%@ 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>


Person 
Java code

private long id;
    
    private String name;
    private String email;
    private String password;
    private String description;

getter setter


结果是:
nullnull
Hibernate: 
  select
  user0_.id as id4_,
  user0_.headPhoto_id as headPhoto2_4_,
  user0_.personInfor_id as personIn3_4_ 
  from
  User user0_,
  Person person1_ 
  where
  user0_.personInfor_id=person1_.id 
  and person1_.email=? 
  and person1_.password=?
登录失败nullnull


为什么太奇怪啦