Display the Attributes for the User to See

Create a page that will query the Directory and return to the user the attribute name and value. Link this page together with an authentication page and the modify attribute page. The user should authenticate into the Directory and see a page prompting the user to view his/her profile or edit his/her profile.

  1. Create an HTML page with a text box that will accept a username and post the username to a servlet.

  2. Open the <html> tag.

  3. Open the <head> tag.

  4. Open the <title> tag and type View Properties of a User and close the title tag.

  5. Close the </head> tag.

  6. Open the <body> tag.

  7. Output an <h1> tag and type Enter the username to view its properties.

  8. Close the </h1> tag.

  9. Open the form tag with the method and action attributes.


<form method = "get" action = "http://edu-qc.provo.novell.com:8080/servlet/view" >

  1. Create a text box with the name "username".

  2. Create submit and reset buttons.

  3. Close the </form> tag.

  4. Close the </body> and </html> tags.

Here is the code for my HTML page view.html.


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<head>
<title>View Properties of a User</title>
</head>

<body bgcolor="#ffc800">
<h1>Enter the username to view its properties</h1>

<form method = "get" action = "http://edu-qc.provo.novell.com:8080/servlet/view" >

<p>
<label>Username: <input type = "text" name="username" size = "50" /></label>
</p>

<p>
<input type="submit" value="Submit" />
<input type="reset" value="Reset" />
</p>

</form>
<hr>
</body>
</html>

  1. Create a servlet that overrides the doGet() method and queries a user object for its properties and displays the properties and values in an HTML table.

  2. Instantiate an LdapConnection bean.

  3. Instantiate an AuthenticateLdap bean and login as admin to the server.

  4. Assign the LdapConnection object to the LDAP connection you created with the Authenticate bean.

  5. Instantiate a ReadLdapEntry bean.

  6. Create a string and concatenate the context with the user's common name.

  7. Set the name of the ReadLdapEntry bean with the setName() method.

  8. Execute the bean.

  9. Output HTML statements to create a table with two columns and as many rows as there are attributes for the object in eDirectory.

  10. Type out.println("<table>");

  11. Type out.println("<thead><th>Attributes</th><th>Values</th></thead>");

  12. Create a for loop that will loop through each attribute, call its value and output it to the screen with HTML.


for (int i = 0; i < rle.getAttributeCount(); i++)
{
out.println("<tr><td>");
out.println(a[i]);
out.println("</td><td>");
out.println(rle.getAttribute(a[i]) + "</td></tr>");
}
out.println("</table>");

  1. Catch an LdapNameNotFoundException and let the user know that the user object could not be found in eDirectory.

Here is my code for the View servlet.


import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import com.novell.ecb.*;
import com.novell.ecb.ldap.*;

public class view extends HttpServlet
{
LdapConnection connection = null;
private static final String CONTENT_TYPE = "text/html";

public void init() throws ServletException
{
}
//Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();

out.println("<html>");
out.println("<head><title>View</title></head>");
out.println("<body bgcolor=\"#ffc800\">");

AuthenticateLdap bean = new AuthenticateLdap();
bean.setURL("ldap://edu-qc.provo.novell.com");
bean.setDN("cn=admin, o=novell");
bean.setPassword("password");

try
{
bean.execute();
}
catch(Exception e)
{
e.printStackTrace();
}
connection = bean.getLdapConnection();

ReadLdapEntry rle = new ReadLdapEntry(connection);
String s = "cn=" + request.getParameter("username") + ", o=novell";
rle.setName(s);
try
{
rle.execute();
out.println("<h3># of Attributes = " + rle.getAttributeCount() +
"</h3><br>");
String[] a = rle.getEntryAttributeNames();
out.println("<table border=1 cellpadding=5>");
out.println("<thead><th>Attributes</th><th>Values</th></thead>");
for (int i = 0; i < rle.getAttributeCount(); i++)
{
out.println("<tr><td>");
out.println(a[i]);
out.println("</td><td>");
out.println(rle.getAttribute(a[i]) + "</td></tr>");
}
out.println("</table>");
}
catch(LdapNameNotFoundException e)
{
out.println("<h1>Sorry, eDirectory did not find the name you
requested.</h1>");
e.printStackTrace(out);
}
catch(Exception e)
{
e.printStackTrace(out);
}
out.println("</body></html>");
}
//Clean up resources
public void destroy()
{
}
}

download sample files
Previous blank Table of Contents blank Next