Posted By

nialace on 11/20/10


Tagged


Versions (?)

jetty hello world


 / Published in: Java
 

un serveur web jetty lancé par programmation

  1. import javax.servlet.http.HttpServletRequest;
  2. import javax.servlet.http.HttpServletResponse;
  3. import javax.servlet.ServletException;
  4.  
  5. import java.io.IOException;
  6.  
  7. import org.eclipse.jetty.server.Server;
  8. import org.eclipse.jetty.server.Request;
  9. import org.eclipse.jetty.server.handler.AbstractHandler;
  10.  
  11. public class Server1 extends AbstractHandler
  12. {
  13. public void handle(String target,
  14. Request baseRequest,
  15. HttpServletRequest request,
  16. HttpServletResponse response)
  17. throws IOException, ServletException
  18. {
  19.  
  20. response.setContentType("text/html;charset=utf-8");
  21. response.setStatus(HttpServletResponse.SC_OK);
  22. baseRequest.setHandled(true);
  23.  
  24. response.getWriter().println("<h1>Hello World</h1>");
  25. }
  26.  
  27. public static void main(String[] args) throws Exception
  28. {
  29. Server server = new Server(8081);
  30. server.setHandler(new Server1());
  31.  
  32.  
  33. server.start();
  34. server.join();
  35. }
  36. }

Report this snippet  

You need to login to post a comment.