我正在尝试使用MongoDB作为后端数据库来实现JSP Web应用程序,并在检索到的数据的“用户名”字段上设置会话。This is my data in the mongo db
以下是我的servlet代码,
公共BasicDBObject authenticateUser(LoginBean loginBean){
String userName = loginBean.getUserName();
String password = loginBean.getPassword();
Mongo mongo = new Mongo("localhost", 27017);
DB db = mongo.getDB("MovieRecommender");
DBCollection table = db.getCollection("Users");
BasicDBObject andQuery = new BasicDBObject();
List<BasicDBObject> obj = new ArrayList<>();
obj.add(new BasicDBObject("Username", userName));
obj.add(new BasicDBObject("Password", password));
andQuery.put("$and", obj);
DBCursor cursor = table.find(andQuery);
while (cursor.hasNext()) {
/**
* This is where my session has to be implemented for the Username
*/
}
}