catch(Exception e){}   可能抛出了异常,但是你并没有处理!所以你以为没有问题,却不知程序转到了catch,catch什么也没做!,所以一直为初始值!
如果你有个好习惯,可能就不用来发贴了。呵呵

解决方案 »

  1.   

    写System.out.println(e);打印出异常可以吗?
      

  2.   

    我觉得是逻辑问题:
    是不是
    if(Factory.getEmployeeDaoInstance().islogin(employee))
                    {
                        if("manager".equals(request.getParameter("ismanager")))
    始终为真?
      

  3.   

    不是啊,我把if("manager".equals(request.getParameter("ismanager")))
                        path = "ManagementDoc.jsp";
    换成path = “ManagementEmployee.jsp”;也没有变,还是到ManagementDoc.jsp
      

  4.   

    path改掉还往那页跳转说明你的servlet没有编译,需要重新启动服务器再进行测试
    建议在前面定义path 的时候先不要赋值,先给个空值进行测试
    下面是你的错误原因:
    你写的DAO实现类出了问题,你检查你的sql语句:SELECT count(*) FROM ………………
    这样的结果集是否一直不为空呢?即便是你的数据库没有符合条件的记录,返回的值也是 0 啊,所以rs.next()永远为真,所以它就会一直往你说的那个页面跳转了啊注:
    "manager".equals(request.getParameter("ismanager"))是很值得推广的写法哦。。
    问题解决了,给分不?我很穷。
      

  5.   

    把语句该了也不行啊path不赋值会提示错误可能未初始化变量path
    错误在这句request.getRequestDispatcher(path).forward(request,response) ;
      

  6.   

    你的sql改了以后是怎么样子的?
    request.getRequestDispatcher(path).forward(req,resp)没有问题啊
    你的数据库里有几个字段?
    查询除了用户名和密码的随便哪个字段,然后再判断rs.next()是否为真
    试试看。
      

  7.   

    用下面的test测试,能得到前面输入的信息
    package com.lys.servlet;
    import com.lys.vo.*;
    import com.lys.dao.*;
    import com.lys.dao.impl.*;
    import com.lys.db.*;
    import com.lys.factory.*;
    import javax.servlet.*;   
    import javax.servlet.http.*;  
    import javax.servlet.ServletException; 
    import java.io.*;   
    import java.util.*; 
    public class test extends HttpServlet
    {
    private static final String CONTENT_TYPE = "text/html;charset = GB2312";
    public void init()throws ServletException
    {
    }
    public   void   doPost(HttpServletRequest   request,   HttpServletResponse   response)   throws  
                            ServletException,IOException 
    {  
    //String name = request.getParameter("name");
    //String password = request.getParameter("password");
    DBConnection dbc = new DBConnection();
    Employee employee = new Employee();
    employee.setname(request.getParameter("name"));
    employee.setpassword(request.getParameter("password"));

    response.sendRedirect("loginfalse.jsp");

    HttpSession session = request.getSession(true);
    session.removeAttribute("username");
    session.setAttribute("username",employee.getname());

    }
    public void doGet(HttpServletRequest request,HttpServletResponse response)throws ServletException,    IOException
    {
    doPost(request,response);
    }
    public void destroy()
    {
    }
    }
      

  8.   

    是不是try catch的问题,我把servlet改成下面的程序,结果跳转到http://localhost:8080/myapp/testservlet就不跳转了,而且是空白页
    package com.lys.servlet;
    import com.lys.vo.*;
    import com.lys.dao.*;
    import com.lys.dao.impl.*;
    import com.lys.db.*;
    import com.lys.factory.*;
    import javax.servlet.*;   
    import javax.servlet.http.*;  
    import javax.servlet.ServletException; 
    import java.io.*;   
    import java.util.*; 
    public class testservlet extends HttpServlet
    {
    private static final String CONTENT_TYPE = "text/html;charset = GB2312";
    public void init()throws ServletException
    {
    }
    public   void   doPost(HttpServletRequest   request,   HttpServletResponse   response)   throws  
                            ServletException,IOException 
    {  
    //String name = request.getParameter("name");
    //String password = request.getParameter("password");
    DBConnection dbc = new DBConnection();
    Employee employee = new Employee();
    employee.setname(request.getParameter("name"));
    employee.setpassword(request.getParameter("password"));


    if("employee".equals(request.getParameter("ismanager")))
    {
    try{
    if(Factory.getEmployeeDaoInstance().islogin(employee))
    response.sendRedirect("ManagementDoc.jsp");
    else
    response.sendRedirect("Search.jsp");
    }
    catch(Exception e){}
    }
    else
    response.sendRedirect("copy.jsp");

    HttpSession session = request.getSession(true);
    session.removeAttribute("username");
    //session.setAttribute("username",name);

    }
    public void doGet(HttpServletRequest request,HttpServletResponse response)throws ServletException,    IOException
    {
    doPost(request,response);
    }
    public void destroy()
    {
    }
    }