This is a continuation of How to return an iText PDF document to the client side
I am trying to pass an Array to a Servelet. I was referred to Send an Array with an HTTP Get however, I do not understand it. This is what I have tried:
List<String[]> listymAwards = new ArrayList<String[]>();
//...
String url = "https://www.awardtracker.org";
String charset = "UTF-8"; // Or in Java 7 and later, use the constant: java.nio.charset.StandardCharsets.UTF_8.name()
//String[] param1 = listymAwards.getParameterValues("param1"); // This attempt is not accepted below by URLEncoder.encode(param1, charset), as it is not a String
String[] param1 = listymAwards.toArray(new String[0]); //This attempt is not accepted below by URLEncoder.encode(param1, charset), as it is not a String
String param2 = scoutName;
String param3 = groupName;
// ...
String query = String.format("param1=%s¶m2=%s¶m3=%s",
URLEncoder.encode(param1, charset),
URLEncoder.encode(param2, charset),
URLEncoder.encode(param3, charset));
URLConnection connection = new URL(url).openConnection();
connection.setDoOutput(true); // Triggers POST.
connection.setRequestProperty("Accept-Charset", charset);
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded;charset=" + charset);
try (OutputStream output = connection.getOutputStream()) {
output.write(query.getBytes(charset));
}
The issue is trying to convert the Array to string to pass the the Servelet at:
String[] param1 = listymAwards.toArray(new String[0]); //This attempt is not accepted below by URLEncoder.encode(param1, charset), as it is not a String
There are a myriad of conversion questions; however non have worked for this.
I am also concerned about how I am going to convert it back, or use it, in the Servelet.