catch(Exception e){} 可能抛出了异常,但是你并没有处理!所以你以为没有问题,却不知程序转到了catch,catch什么也没做!,所以一直为初始值!
如果你有个好习惯,可能就不用来发贴了。呵呵
如果你有个好习惯,可能就不用来发贴了。呵呵
解决方案 »
- websphere 启动应用程序问题
- 怎么深入学习struts2框架
- No getter method for property lockno of bean org.apache.struts.taglib.html.BEAN
- 当FORM的ENCTYPE="multipart/form-data" 时request.getParameter()获取不到值
- 请教关于url乱码问题.
- 求救!!`各位高手能不能提供些学习JAVA方面的好网站
- 零薪兼职,有意请进
- eclipse中deploy EJB出错!!,答对再加100,帮帮兄弟!!!!
- socket
- websocket中进行Spring依赖注入service方法,报错?
- ~~~~~高分,ibatis如何动态加载数据源~~~~~~
- session的问题,怎么在关闭IE的时候删除session中的指定对象?
是不是
if(Factory.getEmployeeDaoInstance().islogin(employee))
{
if("manager".equals(request.getParameter("ismanager")))
始终为真?
path = "ManagementDoc.jsp";
换成path = “ManagementEmployee.jsp”;也没有变,还是到ManagementDoc.jsp
建议在前面定义path 的时候先不要赋值,先给个空值进行测试
下面是你的错误原因:
你写的DAO实现类出了问题,你检查你的sql语句:SELECT count(*) FROM ………………
这样的结果集是否一直不为空呢?即便是你的数据库没有符合条件的记录,返回的值也是 0 啊,所以rs.next()永远为真,所以它就会一直往你说的那个页面跳转了啊注:
"manager".equals(request.getParameter("ismanager"))是很值得推广的写法哦。。
问题解决了,给分不?我很穷。
错误在这句request.getRequestDispatcher(path).forward(request,response) ;
request.getRequestDispatcher(path).forward(req,resp)没有问题啊
你的数据库里有几个字段?
查询除了用户名和密码的随便哪个字段,然后再判断rs.next()是否为真
试试看。
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()
{
}
}
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()
{
}
}