Javability (Java, Zaurus, Linux, Live) by Jean-Marc Autexier, Saarland/Germany
cat /dev/www | egrep 'Java|Linux|Zaurus|ITnews|Live' > blog

24.7.04 12:22 Embedded web server: jetty ( , , , )

Java: ysesterday I looked for embedded java web browser and discovered jetty. Compared to other java web server, the advantages of jetty are:
  • contains a ServletHandler which allows you to write standard servlets and run them in jetty
  • embedded: you don't have to install (and maintain, configure) a web server. The web server (HttpContext) is in your application, you just bind it on a port, register a servlet and that's it. Your application runs like any other Java application.
  • Apache license: good for distribution
  • Small memory consumption: my test application (web server, one servlet) runs with 8MB memory.
  • large installatiton base
Code extracts:
// Create HttpServer and listen on port 8181
HttpServer server = new HttpServer();
HttpListener listener= server.addListener(new InetAddrPort("localhost",8181));

// Create a HTTP context and add it to the server
HttpContext context = new HttpContext();

context.setContextPath("/test/*");
server.addContext(context);
// Create a servlet container and add to the context

ServletHandler servlets = new ServletHandler();
context.addHandler(servlets);

// Map a servlet onto the container
// "/servletX/*" is the URL path under which the servlet will be reachable
// "org.package.MyServlet" is the servlet which will be called
servlets.addServlet("ServletName","/servletX/*","org.package.MyServlet");
That's it. Write your servlet, map it onto the container and run your application. The servlet will be reachable under "http://localhost:8181/servletX".

Few handlers come with jetty: RessourceHandler (serve static content), DumpHandler (dump request and response headers), SecurityHandler (for authentication), ForwardHandler, NotFoundHanlder ...

posted by Jean-Marc Autexier | 3 comments | Permalink | Send to Friends | Google it!
Comments:
What was the JVM that you used?
 
jvm: no idea. probably 1.4.2 or 1.5beta.
 
:-)

http://66.249.93.104/search?q=cache:ert-e3uMC7IJ:jetty.mortbay.org/jetty/tut/HttpServer.html
 

Kommentar veröffentlichen
Subscribe

Locations of visitors to this page
selected blogs
ressources
Security
Unsorted
Fun
Free&Open Software
archives
This is a personal web page. Things said here do not represent the position of my employer.
RSS icons by: FastIcon.com