title: Jetty servlet url and port
body: <p>What is the method call to figure out what is the url and port a jetty servlet is running on? So that I can just print it on the screen, and use it in the client to connect:</p>
  
  <pre><code>url = new URL("trying to figure this out");
  </code></pre>
  
  <p>I am running both the client and the server locally, in eclipse, this is a school project.</p>
  
  <p>Relevant code:</p>
  
  <pre><code>import org.eclipse.jetty.server.Server;
  import org.eclipse.jetty.servlet.DefaultServlet;
  import org.eclipse.jetty.servlet.ServletContextHandler;
  import org.eclipse.jetty.servlet.ServletHolder;
  
  public class ServerMain {
  
      public static void main(String[] args){
          Server server = new Server();
          ServletContextHandler context = 
                  new ServletContextHandler(ServletContextHandler.SESSIONS);
          context.setContextPath("Servlet");
  
          context.setResourceBase("etc/docroot");
  
          server.setHandler(context);
          context.addServlet(new ServletHolder(new MyServer()), "/game");
          DefaultServlet staticFileServlet = new DefaultServlet();
          context.addServlet(new ServletHolder(staticFileServlet), "/*");
          System.out.println("context: " +  context.getContextPath());
          //System.out.println("One valid Port = "
                    + context.getServer().getConnectors()[0].getPort());
          try {
              server.start();
              server.join();
          } catch (Exception e) {
              e.printStackTrace();
          }
      }
  }
  </code></pre>