Java: Simple HTTP Server application that responds in JSON

后端 未结 4 1365
一生所求
一生所求 2021-02-15 19:56

I want to create a very simple HTTP server application in Java.

For example, if I run the server on localhost in port 8080, and I make

4条回答
  •  借酒劲吻你
    2021-02-15 20:46

    You could :

    Install Apache Tomcat, and just drop a JSP into the ROOT project that implements this.

    I second @xehpuk. It's not actually that hard to write your own single class HTTP server using just standard Java. If you want to do it in earlier versions you can use NanoHTTPD, which is a pretty well known single class HTTP server implementation.

    I would personally recommend that you look into Apache Sling (pretty much THE Reference implementation of a Java REST api). You could probably implement your requirements here using Sling without ANY programming at all.

    But as others have suggested, the standard way to do this is to create a java WAR and deploy it into a 'servlet container' such as Tomcat or Jetty etc.

提交回复
热议问题