simplified fileserver example
This commit is contained in:
parent
aeeab8d5bb
commit
00fe5d032e
|
@ -23,7 +23,6 @@ import org.eclipse.jetty.server.Server;
|
|||
import org.eclipse.jetty.server.handler.DefaultHandler;
|
||||
import org.eclipse.jetty.server.handler.HandlerList;
|
||||
import org.eclipse.jetty.server.handler.ResourceHandler;
|
||||
import org.eclipse.jetty.server.handler.gzip.GzipHandler;
|
||||
|
||||
/**
|
||||
* Simple Jetty FileServer.
|
||||
|
@ -41,6 +40,7 @@ public class FileServer
|
|||
// Create the ResourceHandler. It is the object that will actually handle the request for a given file. It is
|
||||
// a Jetty Handler object so it is suitable for chaining with other handlers as you will see in other examples.
|
||||
ResourceHandler resource_handler = new ResourceHandler();
|
||||
|
||||
// Configure the ResourceHandler. Setting the resource base indicates where the files should be served out of.
|
||||
// In this example it is the current directory but it can be configured to anything that the jvm has access to.
|
||||
resource_handler.setDirectoriesListed(true);
|
||||
|
@ -48,11 +48,8 @@ public class FileServer
|
|||
resource_handler.setResourceBase(".");
|
||||
|
||||
// Add the ResourceHandler to the server.
|
||||
GzipHandler gzip = new GzipHandler();
|
||||
server.setHandler(gzip);
|
||||
HandlerList handlers = new HandlerList();
|
||||
handlers.setHandlers(new Handler[] { resource_handler, new DefaultHandler() });
|
||||
gzip.setHandler(handlers);
|
||||
|
||||
// Start things up! By using the server.join() the server thread will join with the current thread.
|
||||
// See "http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/Thread.html#join()" for more details.
|
||||
|
|
Loading…
Reference in New Issue