Embedded Jetty opens. The configuration is done in Java, so you do not need to write a bunch of configuration files. Its very fast - it takes about 2 seconds, and no IDE is required. I usually run it in the terminal and just discard it when I make changes, although you can configure it to dynamically reload changes. If you go to the bottom of this link, you will see detailed information about configuring servlets.
Here is a sample code from the Jetty wiki server, server code:
public class OneServletContext { public static void main(String[] args) throws Exception { Server server = new Server(8080); ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); context.setContextPath("/"); server.setHandler(context); context.addServlet(new ServletHolder(new HelloServlet()),"/*"); context.addServlet(new ServletHolder(new HelloServlet("Buongiorno Mondo")),"/it/*"); context.addServlet(new ServletHolder(new HelloServlet("Bonjour le Monde")),"/fr/*"); server.start(); server.join(); } }
And an example of a servlet:
public class HelloServlet extends HttpServlet { private String greeting="Hello World"; public HelloServlet(){} public HelloServlet(String greeting) { this.greeting=greeting; } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); response.setStatus(HttpServletResponse.SC_OK); response.getWriter().println("<h1>"+greeting+"</h1>"); response.getWriter().println("session=" + request.getSession(true).getId()); } }
source share