View Javadoc

1   // ========================================================================
2   // Copyright (c) 2006-2009 Mort Bay Consulting Pty. Ltd.
3   // ------------------------------------------------------------------------
4   // All rights reserved. This program and the accompanying materials
5   // are made available under the terms of the Eclipse Public License v1.0
6   // and Apache License v2.0 which accompanies this distribution.
7   // The Eclipse Public License is available at 
8   // http://www.eclipse.org/legal/epl-v10.html
9   // The Apache License v2.0 is available at
10  // http://www.opensource.org/licenses/apache2.0.php
11  // You may elect to redistribute this code under either of these licenses. 
12  // ========================================================================
13  
14  package org.eclipse.jetty.embedded;
15  
16  import org.eclipse.jetty.server.Server;
17  import org.eclipse.jetty.servlet.ServletContextHandler;
18  import org.eclipse.jetty.servlet.ServletHolder;
19  
20  public class OneServletContext
21  {
22      public static void main(String[] args) throws Exception
23      {
24          Server server = new Server(8080);
25  
26          ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
27          context.setContextPath("/");
28          server.setHandler(context);
29  
30          // Server content from tmp
31          ServletHolder holder = context.addServlet(org.eclipse.jetty.servlet.DefaultServlet.class,"/tmp/*");
32          holder.setInitParameter("resourceBase","/tmp");
33          holder.setInitParameter("pathInfoOnly","true");
34          
35          // Serve some hello world servlets
36          context.addServlet(new ServletHolder(new HelloServlet()),"/*");
37          context.addServlet(new ServletHolder(new HelloServlet("Buongiorno Mondo")),"/it/*");
38          context.addServlet(new ServletHolder(new HelloServlet("Bonjour le Monde")),"/fr/*");
39  
40          server.start();
41          server.join();
42      }
43  }