jetty 基础

来源:互联网 发布:六轴机器人编程 编辑:程序博客网 时间:2024/06/03 21:17

1.依赖

        <dependency>            <groupId>org.eclipse.jetty</groupId>            <artifactId>jetty-webapp</artifactId>            <version>${jetty.version}</version>        </dependency>        <dependency>            <groupId>org.eclipse.jetty</groupId>            <artifactId>jetty-server</artifactId>            <version>${jetty.version}</version>        </dependency>        <dependency>            <groupId>org.eclipse.jetty</groupId>            <artifactId>jetty-servlet</artifactId>            <version>${jetty.version}</version>        </dependency>

2.常用类

2.1 server

org.eclipse.jetty.server.Server

jetty的server。
org.eclipse.jetty.server.Server.Server(int port)
构造函数,指定port。
void org.eclipse.jetty.server.handler.HandlerWrapper.setHandler(Handler handler)

void org.eclipse.jetty.util.component.AbstractLifeCycle.start() 
启动。
void org.eclipse.jetty.server.Server.join()
函数内部是ThreadPool.join()。
void org.eclipse.jetty.util.component.AbstractLifeCycle.stop()
停止,等待现有的任务执行完毕后再退出。

2.2 context

org.eclipse.jetty.webapp.WebAppContext
void org.eclipse.jetty.server.handler.ContextHandler.setContextPath(String contextPath)
指定Context的path。
void org.eclipse.jetty.server.handler.ContextHandler.setResourceBase(String resourceBase)
设置静态资源的目录。
void org.eclipse.jetty.servlet.ServletContextHandler.addServlet(ServletHolder servlet, String pathSpec)
添加servlet,并在Context的path基础上指定该servlet的path。

2.3 servletHolder

org.eclipse.jetty.servlet.ServletHolder

servlet的持有者。

org.eclipse.jetty.servlet.ServletHolder.ServletHolder(Servlet servlet)

构造函数,指定servlet。
0 0
原创粉丝点击