问题
I have the following Block which filters the data according to the filters I have applied; i.e. it should print only those data that match with "name"
Block<Document> printBlock = new Block<Document>() {
@Override
public void apply(final Document document) {
System.out.println(document.toJson());
}
};
collection.find(eq("name", name)).forEach(printBlock);
I wish to send this data from the current servlet to JSP so that I can display the data. How should I go about this?
EDIT:
JSP Page:
<form action="SearchName" method="post">
Name: <input name="name" size="20" />
<input type="submit" value="Search">
</form>
Servlet:
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String name= request.getParameter("name");
// Create Mongo connection to the DB
MongoClient mongoClient = new MongoClient( "localhost", 27017);
// Select the DB
MongoDatabase database = mongoClient.getDatabase("myDatabase");
// Select the collection
MongoCollection<Document> collection = database.getCollection("myCollection");
Block<Document> printBlock = new Block<Document>() {
@Override
public void apply(final Document document) {
System.out.println(document.toJson());
}
};
collection.find(eq("name", name)).forEach(printBlock);
}
So hence I want only those records which match with "name". I get till here successfully. So next how do I pass them to jsp from servlet and how are they received at JSP?. thanks in advance for help
来源:https://stackoverflow.com/questions/46352116/passing-mongodb-block-from-a-servlet-to-a-jsp