我是一名大學生。現在,我正在執行一個項目,該項目必須使用LDAP連接在登錄過程中驗證用戶的用戶名和密碼。所以,我的網站是使用JSP開發的。我試圖解決代碼的錯誤,但我不能。我是否犯了一些錯誤?javax.naming.InvalidNameException:[LDAP:error code 34 - invalid DN]
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ page import="java.util.*" %>
<%@ page import="javax.naming.*" %>
<%@ page import="java.util.regex.*" %>
<%@ page import="javax.naming.directory.*" %>
<%@ page import="java.util.Hashtable.*" %>
<%@ page import="javax.naming.ldap.*" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<%
String username = request.getParameter("email");
String password = request.getParameter("password");
Hashtable<String, String> env = new Hashtable<String, String>();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, "ldap://ldap-pj.sit.kmutt.ac.th");
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, username);
env.put(Context.SECURITY_CREDENTIALS, password);
try {
//Connect with ldap
new InitialLdapContext(env, null);
//Connection succeeded
System.out.println("Connection succeeded!");
} catch (AuthenticationException e) {
//Connection failed
System.out.println("Connection failed!");
e.printStackTrace();
}
%>
</body>
</html>
我從運行代碼中得到了這個錯誤消息。
HTTP狀態500 -
類型異常報告
消息
描述服務器遇到一個內部錯誤(),從完成此請求防止 它。
例外
org.apache.jasper.JasperException:發生異常處理 JSP頁/ldap_checking.jsp在管線33
30:31:嘗試{32://連接以ldap 33:新的 InitialLdapContext(env,null); 34:35://連接 成功36:System.out.println(「Connection succeeded!」);
堆棧跟蹤: org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:568) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:455) org.apache.jasper .servlet.JspServlet.serviceJspFile(JspServlet.java:390) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334) javax.servlet.http.HttpServlet.service(HttpServlet.java:722)root 原因
javax.servlet.ServletException:javax.naming.InvalidNameException: [LDAP:錯誤代碼34 - 無效的DN] org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:911) org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:840) org.apache.jsp.ldap_005fchecking_jsp._jspService(ldap_005fchecking_jsp。的java:212) org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) javax.servlet.http.HttpServlet.service(HttpServlet.java:722) org.apache.jasper.servlet.JspServletWrapper .service(JspServletWrapper.java:432) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334) javax。 servlet.http.HttpServlet.service(HttpServlet.java:722)root 原因
javax.naming.InvalidNameException:[LDAP:錯誤代碼34 - 無效的DN] com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:3028) com.sun.jndi.ldap.LdapCtx。 processReturnCode(LdapCtx.java:2835) com.sun.jndi.ldap.LdapCtx.connect(LdapCtx.java:2749) com.sun.jndi.ldap.LdapCtx。(LdapCtx.java:316) com.sun。 jndi.ldap.LdapCtxFactory.getUsingURL(LdapCtxFactory.java:193) com.sun.jndi.ldap.LdapCtxFactory.getUsingURLs(LdapCtxFactory.java:211) com.sun.jndi.ldap.LdapCtxFactory.getLdapCtxInstance(LdapCtxFactory。的java:154) com.sun.jndi.ldap.LdapCtxFactory.getInitialContext(LdapCtxFactory.java:84) javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:684) javax.naming.InitialContext.getDefaultInitCtx(InitialContext的的.java:307) javax.naming.InitialContext.init(InitialContext.java:242) javax.naming.ldap.InitialLdapContext(InitialLdapContext.java:153) org.apache.jsp.ldap_005fchecking_jsp._jspService(ldap_005fchecking_jsp.java (HttpServlet.java:722) org.apache.jasper.servlet.JspServletWrapper。服務(JspServletWrapper.java:432) org.apache.jasper.servlet.Js pServlet.serviceJspFile(JspServlet.java:390) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334) javax.servlet.http.HttpServlet.service(HttpServlet.java:722)note備註 full堆棧跟蹤的根本原因可在Apache Tomcat/7.0.27日誌中找到。
的Apache Tomcat/7.0.27
如果你在Mac上,請確保你的build.xml文件中沒有任何'"' – Archmede