0

I would like to send a POST query to a Java servlet from a REACT application. A picture can be sent within this query, as can an array of documents (see picture). In addition, normal parameters such as "durationInMonaten" are also sent. How can I now intercept all these parameters within my servlet?

enter image description here

For the dokumenteArray i tried this:

    StringBuffer bufDoku = new StringBuffer();
    String lineDoku = null;
    try {
        BufferedReader reader = request.getReader();
        while ((lineDoku = reader.readLine()) != null) {
            bufDoku.append(lineDoku);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    JSONObject jsonObjDokument = new JSONObject(bufDoku.toString());
    JSONArray dokumenteArray = jsonObjDokument.getJSONArray("dokumenteArray");

But is there a simple way for the formDate Parameters, like this :

 part = request.getInputStream();
 //Get the Image here
  ....
 //Get the dokumenteArray here
  ....
Captai-N
  • 1,124
  • 3
  • 15
  • 26
  • Instead you can have a POJO of the said schema and use a framework for handling request ex: spring. Automatically you can call obj.getNme(). – Raghuveer Aug 18 '20 at 07:11
  • Does [Send array of objects from servlet to JSP](https://stackoverflow.com/questions/9360223/send-array-of-objects-from-servlet-to-jsp) help you? Have you tried `YourObject[] yourObjects = (YourObject[]) request.getAttribute("dokumenteArray");`? – Ynjxsjmh Aug 18 '20 at 07:45

0 Answers0