Java Reference
In-Depth Information
L ISTING 11.4
11
LDAPTestServlet.java
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import javax.naming.NamingException;
public class LDAPTestServlet extends HttpServlet {
private static final String CONTENT_TYPE = “text/html”;
/**Initialize global variables*/
public void init(ServletConfig config) throws ServletException {
super.init(config);
}
/**Process the HTTP Get request*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// define what results we want from the search
String[] returnAtts = {“cn”,
“sn”,
“givenName”,
“mail”,
“telephoneNumber”};
// get the search criteria from the request
String lName = request.getParameter(“lName”);
// create a search filter, searching on the last name passed in
String filter = “sn=” + lName.trim();
// create and initialize an LDAPManager
LDAPManager lm = new LDAPManager();
lm.setSearchBase(“o=virtuas.com”);
// perform the search
Vector results = null;
try {
results = lm.search(returnAtts, filter);
}
catch (NamingException ex) {
 
Search WWH ::




Custom Search