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

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个回答

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

qq_35206244
lee_zhou 回复qq_35373966: 把前台页面代码传下,页面跳转那一部分
一年多之前 回复
qq_37642368
一条明 回复qq_35373966: ....
一年多之前 回复
qq_35373966
qq_35373966 并没有报错,是只要提交就会跳往成功界面,就算没有用户名和密码
一年多之前 回复

你sql里面放入的语句是固定的不是传入的值

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!