有关web开发……其中的关键步骤:
request.setCharacterEncoding("utf-8");//获取用户名String uName=request.getParameter("username"); //获取密码 String pw=request.getParameter("password"); //编写sql语句 String sql="select * from user where userName='"+username+"' and password='"+password+"'" ; //向数据库发出sql执行查询,查出结果集 ResultSet rs=stmt.executeQuery(sql); //遍历 while(rs.next()){
int ident =rs.getInt("ident"); int userid=rs.getInt("id"); String userName=rs.getString("userName"); //存储用户信息 session.setAttribute("userid",userid); session.setAttribute("userName",userName); if(ident==1){ response.sendRedirect("admin_list_user.jsp"); }else{ response.sendRedirect("HomePage"); } }