Passing MongoDB Block from a servlet to a JSP

拥有回忆 提交于 2020-02-06 10:24:22

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!