Search code examples
javasocketstomcattransfer

How to send Data from Tomcat Server to Client?


I need to write a function that gets a Json via Spring and deliver a Data. The case is that a customer is sending me a Filename and im looking in a database where the file is and send him the data. I only need a little kickstart and someone who can answer me to my Questions:

  • Do I really need Sockets for this?
  • What for a Stream I should use (Its several Datatypes likes Pictures, Documents, Pdf....)
  • How can I identify the Destination to send

Solution

  • You can use Response like this :

    String yourData;
    JsonWriter writer = new JsonWriter(response.getWriter());
        writer.beginObject();
        writer.name("data").value(yourData);
        writer.endObject();
        writer.close();