I am going to use some external libraries to answer your question: Google Gson and Apache IO Utils .
So, you already have a HashMap in your servlet and you want to send it to the applet:
Map<String, String> myMap = new HashMap<String, String>();
And get it in your applet:
String jsonString = IOUtils.toString(conn.getInputStream()); // where 'conn' is an HttpURLConnection IOUtils.closeQuietly(connection.getInputStream()); Gson gson = new GsonBuilder().create(); // The TypeToken is needed when Generics are involved Type typeOfHashMap = new TypeToken<Map<String, String>>() {}.getType(); Map<String, String> myMap = gson.fromJson(jsonString, typeOfHashMap);
What is it. This is just a simple example, but I hope you get some of this.
Of course, you can do it manually instead of using external libraries, but this method is much simpler.
source share