This article address: http://blog.csdn.net/kongxx/article/details/7218787
When embedding running jetty, sometimes you want to start two ports, or through a jetty server to provide a number of different services, such as using 8080来 to specify the default access port, use 8433 to specify HTTPS access port, etc. This can be resolved by creating multiple connector.
1. First create a server class that creates two connector instances, one bound to 8080 ports and the other bound to 9090 ports:
Package com.google.code.garbagecan.jettystudy.sample2;
Import Org.eclipse.jetty.server.Connector;
Import Org.eclipse.jetty.server.Server;
Import Org.eclipse.jetty.server.nio.SelectChannelConnector;
public class MyServer {public
static void Main (string[] args) throws Exception {
Server server = new server ();
selectchannelconnector Connector1 = new Selectchannelconnector ();
Connector1.setport (8080);
Selectchannelconnector Connector2 = new Selectchannelconnector ();
Connector2.setport (9090);
Server.setconnectors (new connector[] {connector1, connector2});
Server.sethandler (New Hellohandler ());
Server.start ();
Server.join ();
}
2. Create a handler class with requests to process all clients
package com.google.code.garbagecan.jettystudy.sample2;
Import java.io.IOException;
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.handler.AbstractHandler; public class Hellohandler extends Abstracthandler {public void handle (String target, Request baserequest, Httpservletreq Uest request, HttpServletResponse response) throws IOException, servletexception {response.setcontenttype ("text/html
; Charset=utf-8 ");
Response.setstatus (HTTPSERVLETRESPONSE.SC_OK);
Baserequest.sethandled (TRUE);
Response.getwriter (). println ("
3. Run the MyServer class and access http://localhost:8080/and http://localhost:9090/separately through the browser.