java - How to display document in table tag? -


how can display document mongodb inside table tag? want display in panel website.

   protected void dopost(httpservletrequest request, httpservletresponse response)         throws servletexception, ioexception {     processrequest(request, response);     response.setcontenttype("text/html;charset=utf-8");     printwriter out = response.getwriter();     //get parameters list     string code = request.getparameter("codename");     string day = request.getparameter("day");     string time = request.getparameter("time");     string price = request.getparameter("price");     if (code == null || code.equals("")             || (day == null || day.equals(""))             || (time == null || time.equals(""))             || (price == null || price.equals(""))) {         request.setattribute("error", "mandatory parameters missing");         requestdispatcher rd = getservletcontext().getrequestdispatcher("/packagespanel.jsp");         rd.forward(request, response);     } else {         //connect mongodb         mongoclient client = new mongoclient("localhost", 27017);         db database = client.getdb("database");         dbcollection collection = database.getcollection("collection");          //insert db         basicdbobject document = new basicdbobject();         document.put("pkg_code", code);         document.put("couple_day", day);         document.put("couple_time", time);         document.put("price", price);         collection.insert(document);         //find , display         mongodatabase db = client.getdatabase("database");         mongocollection<document> coll = db.getcollection("collection");          list<document> documents = (list<document>) coll.find().into(new              arraylist<document>());          (document doc : documents) {             out.println("doc in <table>"); 

if out.print(doc) .. display in document want display in table.

you can try below code convert document html table.

stringbuilder builder = new stringbuilder("<table><thead><tr><th>key1</th><th>key2</th></tr></thead><tbody>"); (document document : documents ) {   builder.append("<tr><td>").append(document.getstring("key1")).append("</td>").append("<td>").append(document.getstring("key2")).append("</td></tr>"); } builder.append("</tbody>").append("</table>"); out.println(builder.tostring()); 

Comments

Popular posts from this blog

PHP and MySQL WP -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

go - golang pprof for c library code -