Can a web service return a stream?

前端 未结 12 1730
眼角桃花
眼角桃花 2021-02-02 09:23

I\'ve been writing a little application that will let people upload & download files to me. I\'ve added a web service to this applciation to provide the upload/download fun

12条回答
  •  攒了一身酷
    2021-02-02 10:04

    It's actually not that hard to "handle the TCP/IP and stream things into your application". Try this...

    class MyServlet extends HttpServlet
    {
        public void doGet(HttpServletRequest request, HttpServletResponse response)
        {
            response.getOutputStream().println("Hello World!");
        }
    }
    

    And that is all there is to it. You have, in the above code, responded to an HTTP GET request sent from a browser, and returned to that browser the text "Hello World!".

    Keep in mind that "Hello World!" is not valid HTML, so you may end up with an error on the browser, but that really is all there is to it.

    Good Luck in your development!

    Rodney

提交回复
热议问题