package jetty.demo; import java.io.IOException; import java.io.PrintWriter; import java.util.Date; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.eclipse.jetty.server.Request; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.handler.AbstractHandler; public class DateTimeDemo extends AbstractHandler { public static void main(String[] args) throws Exception { Server server = new Server(8080); server.setHandler(new DateTimeDemo()); server.start(); server.join(); } @Override public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { if (!request.getRequestURI().startsWith("/date")) return; response.setStatus(HttpServletResponse.SC_OK); response.setContentType("text/html"); PrintWriter page = response.getWriter(); page.println(""); page.println(" "); page.println(" Current time"); page.println(" "); page.println(" "); page.println(new Date()); page.println(" "); page.println(""); baseRequest.setHandled(true); } }