-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMyServer.java
More file actions
32 lines (22 loc) · 751 Bytes
/
MyServer.java
File metadata and controls
32 lines (22 loc) · 751 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
package HttpServer;
import org.eclipse.jetty.server.*;
import org.eclipse.jetty.servlet.ServletHandler;
public class MyServer {
public static void main(String[] args) throws Exception{
// TODO Auto-generated method stub
new MyServer().start();
}
public void start() throws Exception{
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, "/mypath");
servletHandler.addServletWithMapping(MyServlet2.class, "/mypath2");
server.setHandler(servletHandler);
server.start();
server.join();
}
}