Форма регистрации Java jsp для подключения к mongodb (нужна ссылка на пример) - PullRequest
0 голосов
/ 16 мая 2018
I have login block in jsp. Needs to connect it to mongodb. What is the right 
way? Throw POST servlet? Need example link...

<jsp:include page="../main/header.jsp"/>

    <% /* signup block  */ %>
    <div class="container-fluid" style="padding-bottom: 50px">
        <div class = "jumbotron" style="margin-top:50px">
            <div class= "row" style="background- 
image:url(<%=Common.url%>smolink_sky.jpg);width:100%;height:100%;border- 
radius:50%;background-position:bottom left">

                    <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12" 
style="padding-top:50px; padding-bottom: 50px;text-align:right">

                        <p style="text-indent:30px;color:silver; font- 
size:19px"></p><div class="nav-link"> <a href="signup" style="background- 
color:orange; color:white; padding:5px"><b>NEW USER?</b></a></div>
                            <form method="POST" action="sendinglog">
                                <fieldset class="form-group">
                                    <p style="color:white; text-indent:20px; 
text-shadow: 1px 1px 1px #000000 ">USERNAME:</p>
                                        <input type="text" name="yuname" 
size="30" style="border-radius:13%"><br>
                                </fieldset>
                                <fieldset class="form-group">
                                    <p style="color:white; text-indent:20px; 
text-shadow: 1px 1px 1px #000000">PASSWORD:</p>
                                        <input type="text" name="ypname" 
size="30" style="border-radius:13%" ><br>
                                </fieldset>
                                <input type="submit" class="btn btn-info" 
name="Signup" value="SIGNUP" style="margin-left:235px;color:white;text- 
shadow: 
1px 1px 1px #000000">
                            </form>
                        </div>
            </div>
        </div>
    </div>
    <% /* End of signup block  */ %>
    <jsp:include page="../main/footer.jsp"/>

Redirect to this post servlet
import com.mongodb.*;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "sendinglog")
public class sendinglog extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse 
response) throws ServletException, IOException {

        Mongo connection = new Mongo("localhost", 27017);
         DB db = connection.getDB("smol");
         DBCollection collection = db.getCollection("customers");

        String fname = request.getParameter("yfname");
        String email = request.getParameter("yemail");

        BasicDBObject query = new BasicDBObject();
         query.put("_id", fname);
         query.put("email", email);

          collection.insert(query);
        System.out.println("Document inserted");

        DBCursor cursor = collection.find();
        while (cursor.hasNext()) {
            System.out.println(cursor.next());
        }

        cursor.close();
        connection.close();
        response.sendRedirect("index.jsp");
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse 
response) throws ServletException, IOException {

    }
}




And I get a HTTP 500 
HTTP Status 500 – Internal Server Error

    Type Exception Report
    Message Servlet execution threw an exception
    Description The server encountered an unexpected condition that 
prevented it from fulfilling the request.
    Exception
    javax.servlet.ServletException: Servlet execution threw an exception

 org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
    Root Cause
    java.lang.NoClassDefFoundError: com/mongodb/Mongo
        app.model.sendinglog.doPost(sendinglog.java:15)
        javax.servlet.http.HttpServlet.service(HttpServlet.java:660)
        javax.servlet.http.HttpServlet.service(HttpServlet.java:741)

org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
    Root Cause
    java.lang.ClassNotFoundException: com.mongodb.Mongo

org.apache.catalina.loader.WebappClassLoaderBase.loadClass (WebappClassLoaderBase.java:1292) org.apache.catalina.loader.WebappClassLoaderBase.loadClass (WebappClassLoaderBase.java:1121) app.model.sendinglog.doPost (sendinglog.java:15) javax.servlet.http.HttpServlet.service (HttpServlet.java:660) javax.servlet.http.HttpServlet.service (HttpServlet.java:741) org.apache.tomcat.websocket.server.WsFilter.doFilter (WsFilter.java:53) Примечание. Полная трассировка стека основной причины доступна в журналах сервера.

    Apache Tomcat/9.0.7
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...