任何人都可以解释我在这个程序中犯的错误。
我为名为dconnect.java.After
的连接编写了一个java类程序。然后我在JSP中编写了一个程序并与mongodb连接,但是连接没有插入或从mongodb中检索任何值。
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"
import="com.mongodb.BasicDBObject"
import="com.mongodb.DB"
import="com.mongodb.DBCollection"
import="com.mongodb.DBCursor"
import="com.mongodb.MongoClient"
import="java.net.UnknownHostException"
import="com.sun.org.apache.bcel.internal.generic.NEW"
import="com.mongodb.DBObject"
import="com.mongodb.Mongo"
import="java.util.Date"
import="myconnection.test.dconnect"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<!-- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> -->
<meta name="keywords" content=" Employee-Profile " />
<script src="latest/js/jquery.min.js"></script>
<script type="text/javascript" src="common/jquery/jquery-1.11.3.min.js"></script>
<script type="text/javascript" src="latest/js/jquery.validate.min.js"></script>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>jQuery Bootstrap Submenu Plugin Demo</title>
<link rel="stylesheet"
href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css">
<link rel="stylesheet" href="dist/css/bootstrap-submenu.min.css">
<link rel="stylesheet" href="docs.min.css">
<script src="http://code.jquery.com/jquery-2.1.1.min.js" defer></script>
<script
src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"
defer></script>
<script src="dist/js/bootstrap-submenu.min.js" defer></script>
<script src="docs.js" defer></script>
<title>MAANTT | Employee-Profile</title>
<link rel="stylesheet" type="text/css"
href="common/bootstrap/css/bootstrap.min.css">
<link href="/common/bootstrap/css/bootstrap-theme.css" rel="stylesheet"
type="text/css" />
<link href="/common/bootstrap/css/bootstrap-theme.min.css"
rel="stylesheet" type="text/css" />
<link href="/common/bootstrap/css/bootstrap.css" rel="stylesheet"
type="text/css" />
<link href="/common/css/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="/common/bootstrap/js/bootstrap.js">
</script>
<script type="text/javascript"
src="/common/bootstrap/js/bootstrap.min.js">
</script>
<link rel="stylesheet" type="text/css" href="common/css/new.css">
<link href="common/css/new.css" rel="stylesheet" type="text/css" />
<link href="common/css/user_login.css" rel="stylesheet" type="text/css" />
<script>
$(document).ready(function() {
$('.btn-success').popover({
title : "Header",
content : "Blabla",
placement : "bottom"
});
});
</script>
</head>
<body>
<%
String signup=request.getParameter("signup");
if(signup!=null)
{
//here is my logic for creating a user
dconnect mymongo=dconnect.createInstance();
DBCollection collection=mymongo.getCollection("users");
BasicDBObject doc = new BasicDBObject();
doc = new BasicDBObject();
doc.append("email",request.getParameter("email"));
doc.append("pwd",request.getParameter("pwd"));
collection.insert(doc);
session.setAttribute("email",request.getParameter("email"));
response.sendRedirect("userlogin.jsp");
}
%>
<jsp:include page="userloginheader.jsp" />
//<form id="myform" name="myform" method="post"
action="loggedin_homepage.jsp">
<div class="row">
<div class="col-md-6 col-xs-12">
<img class="img-responsive" src="common/image/index.png"
style="margin-top: 3%; width: 100%">
</div>
<div class="container-fluid"
style="margin-top: -120px; background-color: rgba(0, 0, 0, 0.07);">
<div class=" col-md-5 col-xs-12">
<div class="panel panel-default" style="border: 2px solid #036ca0">
<div class="panel-heading"
style=" text-align:center; background-color: #FFFFFF; border: 2px solid #036ca0">Lets
Begin</div>
<div class="panel-body" style="background-color: #D0D0D0">
<div class="form-group">
<div class="row">
<div class="col-md-offset-2 col-md-8 "
style="background-color: #D0D0D0">
<input type="text"
style="border: 2px solid #FFFFFF; background-color:
#D0D0D0; text-align: center;"
required name="user" class="form-control"
id="name"
placeholder="Email Address" maxlength="35">
</div>
</div>
<br>
<div class="form-group">
<div class="row">
<div class="col-md-offset-2 col-md-8">
<input type="password"
style="border: 2px solid #FFFFFF;
background-color: #D0D0D0; text-align: center;"
class="form-control" name="pwd"
id="password" style="border:"
placeholder="Password" maxlength="25">
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-lg-offset-2 col-lg-8 col-xs-12 ">
<button type="submit" name="signup" id="button"
class="buttonAdd btn btn-sm btn-primary
btn-block">Sign
up</button>
</div>
</div>
</div>
<hr>
<div class="footer">
<div class="col-md-offset-2" >By clicking sign up you
agree to user agreement and privacy policy</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>