2016-09-28 52 views
-2
<%-- 
    Document : login 
    Created on : Sep 19, 2016, 11:04:06 AM 
    Author  : admin 
--%> 
<%@page import="com.mongodb.DBCursor"%> 
<%@page import="com.mongodb.DBCollection"%> 
<%@page import="com.mongodb.DB"%> 
<%@page import="com.mongodb.MongoClient"%> 
<%@page contentType="text/html" pageEncoding="UTF-8"%> 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
    "http://www.w3.org/TR/html4/loose.dtd"> 

<html> 
    <head> 

<title>Login</title> 
<!-- Custom Theme files --> 
<link href="css/style.css" rel="stylesheet" type="text/css" media="all"/> 


<!--script--> 
<script src="js/jquery.min.js"></script> 
<script src="js/easyResponsiveTabs.js" type="text/javascript"></script> 
      <script type="text/javascript"> 
       $(document).ready(function() { 
        $('#horizontalTab').easyResponsiveTabs({ 
         type: 'default', //Types: default, vertical, accordion 
         width: 'auto', //auto or any width like 600px 
         fit: true // 100% fit in a container 
        }); 
       }); 

</script> 
<!--script--> 

<%@page import="mongo.*" %> 
</head> 
    </head> 
    <body> 
     <%-- <form action="MongoConnection">--%> 



<%try{ 

    // To connect to mongodb server 
    MongoClient mongoClient = new MongoClient("localhost" , 27017); 

    // Now connect to your databases 
    DB db = mongoClient.getDB("nandha"); 
    System.out.println("Connect to database successfully"); 


    DBCollection coll = db.getCollection("priya"); 
    System.out.println("Collection admin selected successfully"); 

    DBCursor cursor = coll.find(); 
    int i = 1; 

    while (cursor.hasNext()) { 
     System.out.println("Inserted Document: "+i); 
     System.out.println(cursor.next()); 
     i++; 
    } 

    }catch(Exception e){ 
    System.err.println(e.getClass().getName() + ": " + e.getMessage()); 
    } 

}%>我是新來的MongoDB和jsp,我試圖使用的MongoDB數據庫連接的NetBeans創建登錄頁面

   <form method="post" action="product-list.jsp"> 
     <div class="head"> 
     <div class="logo"> 
      <div class="logo-top"> 
       <h1>Syzygy Spa Login</h1> 
      </div> 
      <div class="logo-bottom"> 
       <img src="images/logo.png" > 
      </div> 
     </div> 
     <div class="login"> 
      <div class="sap_tabs"> 
       <div id="horizontalTab" style="display: block; width: 100%; margin: 0px;"> 
        <ul class="resp-tabs-list"> 
         <li class="resp-tab-item" aria-controls="tab_item-0" role="tab"><span>Login Here ...</span></li> 
         <div class="clearfix"></div> 
        </ul> 
        <div class="resp-tabs-container"> 
         <div class="tab-1 resp-tab-content" aria-labelledby="tab_item-0"> 
          <div class="login-top"> 
           <form> 
            <input type="text" class="email" placeholder="Email" required/> 
            <input type="password" class="password" placeholder="Password" required/> 
           </form> 
           <div class="login-bottom login-bottom1"> 
            <div class="submit"> 
             <input type="submit" value="LOGIN"/> 
            </div> 
            <div class="clear"></div> 
           </div> 
          </div> 
         </div> 

        </div> 
       </div> 
      </div> 
     </div> 
     <div class="clear"></div> 
    </div> 

    </body> 
</html> 

但我有錯誤MongoDB中連接

端口:本地主機:27017 我的數據庫名稱:nandha。 我的集合名稱:普里亞

{ 「_id」:{ 「$ OID」: 「57e3b941ed64421e189a8a0b」}, 「名」: 「nandha」, 「年齡」:26,密碼:「bharani, 」創建日期「: { 「$日期」: 「2016-09-22T10:58:09.792Z」}}

+0

請提供一些更多的解釋你的代碼,你正在嘗試做什麼以及你遇到什麼問題*完全是*。很難在數十甚至數百行代碼中發現錯誤,請閱讀[如何創建*最小*,完整,a nd可驗證的例子](http://stackoverflow.com/help/mcve)和[我如何問一個好問題?](http://stackoverflow.com/help/how-to-ask)。然後,更新並*改進您的問題*。 –

回答

相關問題