tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@locus.apache.org
Subject cvs commit: jakarta-tomcat-4.0/webapps/examples/WEB-INF/classes JndiServlet.java
Date Thu, 02 Nov 2000 06:16:18 GMT
remm        00/11/01 22:16:17

  Added:       webapps/examples/WEB-INF/classes JndiServlet.java
  Log:
  - Add a naming servlet example
  
  Revision  Changes    Path
  1.1                  jakarta-tomcat-4.0/webapps/examples/WEB-INF/classes/JndiServlet.java
  
  Index: JndiServlet.java
  ===================================================================
  /* $Id: JndiServlet.java,v 1.1 2000/11/02 06:16:16 remm Exp $
   *
   */
  
  import java.io.IOException;
  import java.io.PrintWriter;
  import java.util.Enumeration;
  import java.util.Hashtable;
  import javax.servlet.*;
  import javax.servlet.http.*;
  import javax.naming.NamingException;
  import javax.naming.Context;
  import javax.naming.InitialContext;
  import javax.naming.NamingEnumeration;
  import javax.naming.directory.InitialDirContext;
  
  /**
   * Demonstration of the web application environment support.
   *
   * @author Remy Maucherat
   */
  
  public class JndiServlet 
      extends HttpServlet {
  
  
      public void doGet(HttpServletRequest request, HttpServletResponse response)
          throws ServletException, IOException {
          
          PrintWriter out = response.getWriter();
          response.setContentType("text/plain");
          
          Context ctx = null;
          
          try {
              ctx = new InitialContext();
          } catch (NamingException e) {
              out.println("Couldn't build an initial context : " + e);
              return;
          }
          
          try {
              Object value = ctx.lookup("java:/comp/env/maxExemptions");
              out.println("Simple lookup test : ");
              out.println("Max exemptions value : " + value);
          } catch (NamingException e) {
              out.println("JNDI lookup failed : " + e);
          }
          
          try {
              Context envCtx = (Context) ctx.lookup("java:/comp/env/");
              out.println("list() on /comp/env Context : ");
              NamingEnumeration enum = ctx.list("java:/comp/env/");
              while (enum.hasMoreElements()) {
                  out.print("Binding : ");
                  out.println(enum.nextElement().toString());
              }
              out.println("listBindings() on /comp/env Context : ");
              enum = ctx.listBindings("java:/comp/env/");
              while (enum.hasMoreElements()) {
                  out.print("Binding : ");
                  out.println(enum.nextElement().toString());
              }
          } catch (NamingException e) {
              out.println("JNDI lookup failed : " + e);
          }
          
      }
      
      
  }
  
  
  
  

Mime
View raw message