protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        
        try (PrintWriter out = response.getWriter()) {
            //Hent alle valgfag
            JerseyClientVote client = new JerseyClientVote();
            String json = client.findAll_JSON(String.class);
            System.out.println(json);

//                Gson gson = new Gson();
            JsonArray jsonArray = new JsonArray();
            JsonParser parser = new JsonParser();

            jsonArray = (JsonArray) parser.parse(json);
            Map<String, String> studNameMap = new HashMap(); //KEY: StudId VALUE: firstname + lastname
            Map<String, Map<String, String> > studSubjMap = new HashMap(); //KEY: StudId VALUE: subjMap
            Map<String, String> subjMap = new HashMap();     //KEY: SubjId VALUE: Prioritet 1/2

            for (int i = 0; i < jsonArray.size(); i++) {
                //Saml studerende op og gem...
                JsonObject vote = (JsonObject) jsonArray.get(i);
                JsonObject student = (JsonObject)vote.get("studentid");
                JsonObject subject = (JsonObject)vote.get("subjectid");
                
                String studId = student.get("lid").toString();
                String name = student.get("firstname").toString()+ " " 
                            + student.get("lastname").toString();
                studNameMap.put(studId, name);
//
                //Opsamling af valgfag og prioritet
                String subjId = subject.get("id").toString();
                try {
                    subjMap = new HashMap();
                    subjMap = studSubjMap.get(studId);
                    subjMap.put(subjId, vote.get("priority").toString());
                } catch (NullPointerException ex) {
//                    ex.printStackTrace();
                    subjMap = new HashMap();
                    subjMap.put(subjId, vote.get("priority").toString());
                }
                studSubjMap.put(studId, subjMap);

            }
            request.getSession().setAttribute("studentname", studNameMap);
            request.getSession().setAttribute("studentsubjects", studSubjMap);

            client.close();

            //testudskrift af HashMaps
            Iterator it = studNameMap.entrySet().iterator();
            StringBuilder textList = new StringBuilder();
            textList.append("{\"student\":[");
            int j = 0;
            while (it.hasNext()) {
                Map.Entry pairs = (Map.Entry) it.next();
                String key = pairs.getKey().toString();
                String name = pairs.getValue().toString();
                String firstname = name.split(" ")[0];
                String lastname = name.split(" ")[1];
//                System.out.println(key + " = " + firstname);
                
//                it.remove(); // avoids a ConcurrentModificationException
                //*****
                subjMap = null;
                subjMap = studSubjMap.get(key);
//                System.out.println("***Debug*** " + subjMap.toString());
                
                //Byg hele datagrundlaget ind i en string.
                if (j!=0){textList.append(",");}
                j++;
                textList.append("{\"id\":\""+key+"\", ");
                textList.append("\"firstname\":"+firstname+",");
                textList.append("\"lastname\":"+lastname+", ");
                
                textList.append("\"subjects\":[{");
                Iterator it2 = subjMap.entrySet().iterator();
                int i =0;
                while (it2.hasNext()) {
                    Map.Entry pairs2 = (Map.Entry) it2.next();
                    String subjid = pairs2.getKey().toString();
                    String subjprio = pairs2.getValue().toString();
//                    System.out.println("subjectid: "+ subjid + " Priority: " + subjprio);
                    if (i!=0){textList.append(",{");}
                    textList.append("\"id\":\""+subjid+"\",");
                    textList.append("\"prio\": \""+subjprio+"\"}");
                    i++;
        }
                //*****
                textList.append("]}");
    }
            textList.append("]}");
            System.out.println(textList);
            out.println(textList);
        }
    }