当前位置: 代码迷 >> Java Web开发 >> 第一次如果登录异常,那么第二次便不能再登录了?为什么?哪位高手空闲解决一上这个有关问题?
  详细解决方案

第一次如果登录异常,那么第二次便不能再登录了?为什么?哪位高手空闲解决一上这个有关问题?

热度:5304   发布时间:2013-02-25 21:12:31.0
第一次如果登录错误,那么第二次便不能再登录了??为什么??谁空闲解决一下这个问题???????????????
登录表单:

HTML code
<form action="login">        <table width="22%" border="1" align="center" cellspacing="0" cellpadding="3">            <tr><td colspan="2" align="center"><span class="STYLE3">用户登录</span></td></tr>            <tr>             <td width="23%">用户名</td>            <td width="77%"><input type="text" name="employee.name"/></td>            </tr>            <tr>            <td width="23%">密码</td>            <td width="77%"><input type="password" name="employee.password"/></td>            </tr>            <tr><td colspan="2"><div align="center"><input type="submit"value="登录" /><input type="reset" value="重置"/></div></td></tr>        </table>    </form>    <s:fielderror></s:fielderror>


struts2配置:

XML code
    <package name="default" namespace="/" extends="struts-default">     <action name="login" class="EmployeeAction" method="login"> //EmployeeAction在spring中已经配置。             <result name="success">/show.jsp</result>             <!--<result name="success" type="redirect">                 <param name="location">/show.jsp</param>                 <param name="loginuser">${loginuser}</param>             </result>              --><result name="err">/login.jsp</result>          </action>


EmployeeAction:

Java code
public String login(){        Employee employee1=null;        try{            employee1=this.employeeServiceI.login(employee);        }catch(Exception e){            e.printStackTrace();        }        if(employee1!=null){            if(employee1.getPassword().equals(employee.getPassword())){                this.session.put("loginuser", employee1);                return SUCCESS;            }else{                this.addFieldError("err", "密码错误");                return "err";            }        }else{            this.addFieldError("errr", "用户不存在!请注册");            return "err";        }            }


下面是EmployeeDAOImpl中的实现类:

Java code
public Employee login(Employee employee1) {                  Session session=this.sessionFactory.getCurrentSession();        Employee employee=null;        try {            Query query=session.createQuery("from Employee e where e.name=?");                         query.setParameter(0, employee1.getName());                          if(query.list()!=null)             {             employee=(Employee) query.list().get(0);                  }else{                  employee=null;             }        } catch (Exception e) {            // TODO: handle exception            e.printStackTrace();        }     return employee;    }


我的思路就是通过表单提交对象给EmployeeAction,然后把employee中的name拿到数据库中去查询出一个对象,然后再将这个对象的密码和表单提交的对象的密码进行比较。在启动tomcat以后,第一次登录,如果输入正确的用户名和密码就能直接去show.jsp。但是如果我一旦输入错误的用户名或者密码进去登录,当然会失败,但是我再重新输入正确的就不能成功了。
  相关解决方案