用 Java 创建一个简单的 HTTP 服务器? [英] Create a simple HTTP server with Java?

查看:42
本文介绍了用 Java 创建一个简单的 HTTP 服务器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 Java 创建简单 HTTP 服务器的最简单方法是什么?是否有任何公共图书馆可以促进这一点?我只需要响应GET/POST,我不能使用应用服务器.

What's the easiest way to create a simple HTTP server with Java? Are there any libraries in commons to facilitate this? I only need to respond to GET/POST, and I can't use an application server.

实现这一目标的最简单方法是什么?

What's the easiest way to accomplish this?

推荐答案

使用 Jetty.这是 嵌入 Jetty.(这是一个过时的教程.)

Use Jetty. Here's the official example for embedding Jetty. (Here's an outdated tutorial.)

Jetty 非常轻量级,但它确实提供了一个 servlet 容器,这可能与您对使用应用程序服务器"的要求相矛盾.

Jetty is pretty lightweight, but it does provide a servlet container, which may contradict your requirement against using an "application server".

您可以将 Jetty 服务器嵌入到您的应用程序中.Jetty 允许嵌入式或 servlet 容器选项.

You can embed the Jetty server into your application. Jetty allows EITHER embedded OR servlet container options.

这里有一个更快速的入门教程以及源代码.

Here is one more quick get started tutorial along with the source code.

这篇关于用 Java 创建一个简单的 HTTP 服务器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆