-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMyHttpServer.java
More file actions
38 lines (29 loc) · 916 Bytes
/
MyHttpServer.java
File metadata and controls
38 lines (29 loc) · 916 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package HttpServerClient;
import org.eclipse.jetty.server.*;
import org.eclipse.jetty.servlet.*;
import com.google.gson.*;
import HttpServerClient.MyServlet;
public class MyHttpServer {
public void start() {
Server server = new Server();
ServerConnector http = new ServerConnector(server);
http.setHost("127.0.0.1");
http.setPort(8081);
server.addConnector(http);
// ServletHandler servletHandler = new ServletHandler();
// servletHandler.addServletWithMapping(MyServlet.class, "/");
// server.setHandler(servletHandler);
ServletContextHandler context = new ServletContextHandler();
context.setContextPath("/");
context.setAttribute("server.name", "myServer");
context.addServlet(MyServlet.class, "/");
server.setHandler(context);
try {
server.start();
server.join();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}