jetty是什么 jetty的翻译

作者: 用户投稿 阅读:17 点赞:0

Jetty是一个开源的Java HTTP服务器和Java Servlet容器,由Eclipse基金会维护。它可以作为独立的Web服务器运行,也可以嵌入到应用程序中,以提供HTTP和Servlet支持。

1. 功能特性:Jetty提供了许多功能,包括HTTP/2、WebSocket、OSGi、JNDI、JAAS、JMX、JASPI、AJP、热部署、请求日志和SSL等。

2. 架构:Jetty使用面向对象的架构,将所有内容封装在一个可重用的模块中,并使用插件来添加新功能。

3. 优势:Jetty的优势之一是它的体积小,速度快,易于集成和部署,而且不需要复杂的配置。

4. 示例代码:是一个简单的Jetty服务器示例:

java // Create a basic Jetty server object that will listen on port 8080. Note that if you set this to port 0 // then a randomly available port will be assigned that you can either look in the logs for the port, // or programmatically obtain it for use in test cases. Server server = new Server(8080); // The WebAppContext is the entity that controls the environment in which a web application lives and // breathes. In this example the context path is being set to "/" so it is suitable for serving root context // requests and then we see it setting the location of the war. A whole host of other configurations are // available, ranging from configuring to support annotation scanning in the webapp (through PlusConfiguration) // to choosing where the webapp will unpack itself. WebAppContext webapp = new WebAppContext(); webapp.setContextPath("/"); webapp.setWar("/path/to/my/webapp/dir/or/war/file.war"); // A WebAppContext is a ContextHandler as well so it needs to be set to the server so it is aware of where to // send the appropriate requests. server.setHandler(webapp); // Start things up! By using the server.join() the server thread will join with the current thread. // See "http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/Thread.html#join()" for more details. server.start(); server.join();

标签:

  • 评论列表 (0