public static void main(String[] args) throws SQLException { UserDao dao = new UserDao() ; List<User> ls = new ArrayList<User>(); ls = dao.query(); for(int i=0 ; i<ls.size() ; i++){ System.out.print("账号:"+ls.get(i).getUsername()+" , "); System.out.println("密码:"+ls.get(i).getPassword()); } }
以上代码我用JAVA运行能在控制台输出我数据库中的几个数据
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("utf-8"); UserDao dao = new UserDao() ; List<User> ls = new ArrayList<User>(); try { ls=dao.query(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } String name = request.getParameter("name"); String password = request.getParameter("password"); for(int i=0 ; i<ls.size() ; i++){ if(ls.get(i).getUsername().equals(name) && ls.get(i).getPassword().equals(password)){ request.getRequestDispatcher("/Success.jsp").forward(request,response); } else{ request.getRequestDispatcher("/Fail.jsp").forward(request,response); } } }
然后运行这个就报错了
我没用数据库的时候用if判断就能跳转页面
所以我感觉其他的代码应该没错 就把这部分粘出来了
String name = request.getParameter("name"); String password = request.getParameter("password"); if("a".equals(name) && "a".equals(password)){ request.getRequestDispatcher("/Success.jsp").forward(request,response); } else{ request.getRequestDispatcher("/Fail.jsp").forward(request,response); } }
上面代码是不用数据库就可以正常跳转 所以其他的代码应该没问题
慕粉4208695
慕妹5461943
你好小Song
对代码有洁癖
慕粉4208695
慕莱坞4108056
相关分类