weixin_42363471
weixin_42363471
2010-05-06 12:10

struts2登陆问题·急~~~~~~只有这么点分了T.T

  • struts

我已经被这个苦恼的问题 折磨好半天了。。高手们帮我看看问题出在哪了  总是空指针异常 可是我检查了很仔细了还是没看出来哪里不对。急~~~~
登陆页面

  <tr>
        <td width="70" align="center">用户名:</td>
        <td><input name="user.username" type="text" class="id" style="width:160px;"/></td>
      </tr>
      <tr>
        <td width="70" align="center">密&nbsp;&nbsp;码:</td>
        <td><input name="user.password" type="password" class="id" style="width:160px;"/></td>
      </tr>

UserDAO

public class UserDAO {
    private JdbcTemplate jt;

    public JdbcTemplate getJt() {
        return jt;
    }

    public void setJt(JdbcTemplate jt) {
        this.jt = jt;
    }
    
    public User getUser(User user){
        String sql="select count(*) from user where username='"
            + user.getUsername() + "' and password='" + user.getPassword()
            + "'";
        
        int tt=jt.queryForInt(sql);
        if(tt>0)
            return user;    
        else
            return null;
    }

 UserService

public class UserService {
     private UserDAO userDAO;

    public UserDAO getUserDAO() {
        return userDAO;
    }

    public void setUserDAO(UserDAO userDAO) {
        this.userDAO = userDAO;
    }
    
    public boolean isLogin(User user){
        
        if(userDAO.getUser(user)!=null){    
            return true;
        }
        return false;
    }

UserAction

public class UserAction extends ActionSupport {
    
    private UserService userService;
    private User user;
        public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }
        public UserService getUserService() {
        return userService;
    }

    public void setUserService(UserService userService) {
        this.userService = userService;
    }
public String execute() throws Exception{
        
        if(userService.isLogin(user)){
            ActionContext context = ActionContext.getContext();
            Map session = context.getSession();
            session.put("user", user);
            System.out.println("判断ACTION已经执行");
            return "success";
            
         }
        else
        {
                        return "input";
        }

        }
  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

15条回答