qq_35373966 2018-02-19 09:38 采纳率: 0%
浏览 813
已结题

登录的检查功能无效,错在哪?

index.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>


登录页面




/s:textfield
/s:password
/s:submit
/s:form


struts.xml



firstpage.jsp
index.jsp


LogAction
public class LogAction extends ActionSupport{
private String name;
private String pwd;

public String getName() {
    return name;
}

public String getPwd() {
    return pwd;
}

public void setName(String name) {
    this.name = name;
}

public void setPwd(String pwd) {
    this.pwd = pwd;
}

@Override
public String execute() throws Exception {
    Login();
    return super.execute();
}

public String Login(){
    ActionContext context = ActionContext.getContext();
    HttpServletRequest request = ServletActionContext.getRequest();
    String name = (String) request.getParameter("name");
    String pwd = (String) request.getParameter("pwd");
    if (name.isEmpty()  ||  pwd.isEmpty()){
        return ERROR;
    }else {
        Usee login = UseeDao.login(name, pwd);
        if(login!=null){
            return SUCCESS;
        }else {
            return ERROR;
        }
    }

UseeDao
public class UseeDao {
public static Usee login(String name, String pwd) {

    Session session = HibernateSessionFactory.getSession();
    List<Usee> list = new ArrayList<>();

    list = session.createQuery("from Usee u where u.name=? and u.password=?").setParameter(0, name).setParameter(1, pwd).list();
    if (list.size() != 0) {
        Usee usee = list.get(0);
        return usee;
    } else {
        return null;
    }
}

}

Usee.java
public class Usee implements Serializable {
private int id;
private String num;
private String name;
private String password;

public Usee(){}

@Id
@Column(name = "ID", nullable = false)
public int getId() {
    return id;
}

public void setId(int id) {
    this.id = id;
}

@Basic
@Column(name = "NUM", nullable = true, length = 45)
public String getNum() {
    return num;
}

public void setNum(String num) {
    this.num = num;
}

@Basic
@Column(name = "NAME", nullable = true, length = 45)
public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}

@Basic
@Column(name = "PASSWORD", nullable = true, length = 45)
public String getPassword() {
    return password;
}

public void setPassword(String password) {
    this.password = password;
}

@Override
public boolean equals(Object o) {
    if (this == o) return true;
    if (o == null || getClass() != o.getClass()) return false;
    Usee usee = (Usee) o;
    return id == usee.id &&
            Objects.equals(num, usee.num) &&
            Objects.equals(name, usee.name) &&
            Objects.equals(password, usee.password);
}

@Override
public int hashCode() {

    return Objects.hash(id, num, name, password);
}

}

HibernateSessionFactory.java
public class HibernateSessionFactory {

/** 
 * Location of hibernate.cfg.xml file.
 * Location should be on the classpath as Hibernate uses  
 * #resourceAsStream style lookup for its configuration file. 
 * The default classpath location of the hibernate config file is 
 * in the default package. Use #setConfigFile() to update 
 * the location of the configuration file for the current session.   
 */
private static String CONFIG_FILE_LOCATION = "/hibernate.cfg.xml";
private static final ThreadLocal<Session> threadLocal = new ThreadLocal<Session>();
private  static Configuration configuration = new Configuration();    
private static org.hibernate.SessionFactory sessionFactory;
private static String configFile = CONFIG_FILE_LOCATION;

static {
    try {
        configuration.configure(configFile);
        sessionFactory = configuration.buildSessionFactory();
    } catch (Exception e) {
        System.err
                .println("%%%% Error Creating SessionFactory %%%%");
        e.printStackTrace();
    }
}
private HibernateSessionFactory() {
}

/**
 * Returns the ThreadLocal Session instance.  Lazy initialize
 * the <code>SessionFactory</code> if needed.
 *
 *  @return Session
 *  @throws HibernateException
 */
public static Session getSession() throws HibernateException {
    Session session = (Session) threadLocal.get();

    if (session == null || !session.isOpen()) {
        if (sessionFactory == null) {
            rebuildSessionFactory();
        }
        session = (sessionFactory != null) ? sessionFactory.openSession()
                : null;
        threadLocal.set(session);
    }

    return session;
}

/**
 *  Rebuild hibernate session factory
 *
 */
public static void rebuildSessionFactory() {
    try {
        configuration.configure(configFile);
        sessionFactory = configuration.buildSessionFactory();
    } catch (Exception e) {
        System.err
                .println("%%%% Error Creating SessionFactory %%%%");
        e.printStackTrace();
    }
}

/**
 *  Close the single hibernate session instance.
 *
 *  @throws HibernateException
 */
public static void closeSession() throws HibernateException {
    Session session = (Session) threadLocal.get();
    threadLocal.set(null);

    if (session != null) {
        session.close();
    }
}

/**
 *  return session factory
 *
 */
public static org.hibernate.SessionFactory getSessionFactory() {
    return sessionFactory;
}

/**
 *  return session factory
 *
 *  session factory will be rebuilded in the next call
 */
public static void setConfigFile(String configFile) {
    HibernateSessionFactory.configFile = configFile;
    sessionFactory = null;
}

/**
 *  return hibernate configuration
 *
 */
public static Configuration getConfiguration() {
    return configuration;
}

}

  • 写回答

2条回答 默认 最新

  • hxaun 2018-02-19 12:06
    关注

    报啥错啊,你打断点看一下吧。

    评论

报告相同问题?

悬赏问题

  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥15 MCNP里如何定义多个源?
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏