Guest User

Untitled

a guest
Dec 13th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. // servlet is local to the app
  2. String requestURL = request.getRequestURL().toString();
  3. String servletPath = request.getServletPath();
  4. String serverPath = requestURL.substring(0,requestURL.indexOf(servletPath));
  5. URL url = new URL(serverPath + "/getScores");
  6.  
  7. URLConnection conn = url.openConnection();
  8. conn.setConnectTimeout(12000);
  9. InputStream is = conn.getInputStream();
  10.  
  11. StringWriter writer = new StringWriter();
  12. IOUtils.copy(is, writer, "UTF-8");
  13.  
  14. String jsonStr = writer.toString();
  15.  
  16. Gson gson = new Gson();
  17. Type listType = new TypeToken<List<ScoreRecord>>() {}.getType();
  18. List<ScoreRecord> scores = gson.fromJson(jsonStr, listType);
Add Comment
Please, Sign In to add comment