4

私は大学生です。現在、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) 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: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 ログで入手できます。

アパッチ トムキャット/7.0.27

4

2 に答える 2