Note that there are some explanatory texts on larger screens.

plurals
  1. POConvenient way to parse incoming multipart/form-data parameters in a Servlet
    primarykey
    data
    text
    <p>Is there any convenient way to read and parse data from incoming request.</p> <p>E.g client initiate post request</p> <pre><code>URLConnection connection = new URL(url).openConnection(); connection.setDoOutput(true); connection.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + boundary); PrintWriter writer = null; try { OutputStream output = connection.getOutputStream(); writer = new PrintWriter(new OutputStreamWriter(output, charset), true); // true = autoFlush, important! // Send normal param. writer.println("--" + boundary); writer.println("Content-Disposition: form-data; name=\"param\""); writer.println("Content-Type: text/plain; charset=" + charset); writer.println(); writer.println(param); </code></pre> <p>I’m not able to get param using <code>request.getParameter("paramName")</code>. The following code</p> <pre><code>BufferedReader reader = new BufferedReader(new InputStreamReader( request.getInputStream())); StringBuilder sb = new StringBuilder(); for (String line; (line = reader.readLine()) != null;) { System.out.println(line); } </code></pre> <p>however displays the content for me </p> <pre><code>-----------------------------29772313742745 Content-Disposition: form-data; name="name" J.Doe -----------------------------29772313742745 Content-Disposition: form-data; name="email" abuse@spamcop.com -----------------------------29772313742745 </code></pre> <p>What is the best way to parse incoming request? I don’t want to write my own parser, probably there is a ready solution.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload