如何检查存在的用户并传入 mongoCollection 以在会话中设置?
how to check exist user and pass in mongoCollection for set in session?
我可以在 if() 中写什么来检查集合中是否存在从登录表单中获取的参数?
String username = request.getParameter("user");
String password = request.getParameter("pass");
String[] remeberusr = request.getParameterValues("remember");
MongoClient client = new MongoClient("localhost", 27017);
DB db = client.getDB("mydb");
DBCollection collection = db.getCollection("members");
BasicDBObject setquery = new BasicDBObject();
setquery.put("user", username);
setquery.put("pass", password);
DBCursor result = collection.find(setquery);
if (?)) {
HttpSession session = request.getSession();
session.setAttribute("user", username);
session.setAttribute("pass", password);
session.setAttribute("remember", remeberuser);
response.sendRedirect("session.jsp");
} else {
out.print("user and pass incorrected!");
}
我过去曾将此方法用于 MySQL 数据库,希望它有助于获取存储在数据库中的用户名和密码,并使用 for 循环和 in if 使用 (==) 运算符
if(hasNext())
hasNext() 检查是否有另一个对象可用
我可以在 if() 中写什么来检查集合中是否存在从登录表单中获取的参数?
String username = request.getParameter("user");
String password = request.getParameter("pass");
String[] remeberusr = request.getParameterValues("remember");
MongoClient client = new MongoClient("localhost", 27017);
DB db = client.getDB("mydb");
DBCollection collection = db.getCollection("members");
BasicDBObject setquery = new BasicDBObject();
setquery.put("user", username);
setquery.put("pass", password);
DBCursor result = collection.find(setquery);
if (?)) {
HttpSession session = request.getSession();
session.setAttribute("user", username);
session.setAttribute("pass", password);
session.setAttribute("remember", remeberuser);
response.sendRedirect("session.jsp");
} else {
out.print("user and pass incorrected!");
}
我过去曾将此方法用于 MySQL 数据库,希望它有助于获取存储在数据库中的用户名和密码,并使用 for 循环和 in if 使用 (==) 运算符
if(hasNext())
hasNext() 检查是否有另一个对象可用