我是一名大学生。现在,我正在做一个必须使用 LDAP 连接来验证登录过程中用户的用户名和密码的项目。所以,我的网站是使用 JSP 开发的。我试图解决代码错误,但我不能。我在上面犯了一些错误吗?
<%@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:在第 33 行处理 JSP 页面 /ldap_checking.jsp 时发生异常
30: 31: try { 32: //连接 ldap 33: new InitialLdapContext(env, null); 34: 35: //连接成功 36: System.out.println("连接成功!");
堆栈跟踪: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) 根本原因
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。服务(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) 根本原因
javax.naming.InvalidNameException:[LDAP:错误代码 34 - 无效 DN] com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:3028) com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:第2835章 不知道怎么办.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:97) 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) 注意 Apache Tomcat/7.0.27 日志中提供了根本原因的完整堆栈跟踪。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) 注意 根本原因的完整堆栈跟踪可在Apache Tomcat/7.0.27 日志。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) 注意 根本原因的完整堆栈跟踪可在Apache Tomcat/7.0.27 日志。722) 注意 Apache Tomcat/7.0.27 日志中提供了根本原因的完整堆栈跟踪。722) 注意 Apache Tomcat/7.0.27 日志中提供了根本原因的完整堆栈跟踪。
Apache Tomcat/7.0.27