I have this code:
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    PrintWriter printWriter = response.getWriter();
    JSONArray arrayObj=new JSONArray();
    TimeTableDAO timeTable = new TimeTableDAO();
    ArrayList<String[]> data = timeTable.getTimeTableData();
    for (int i = 0; i < data.size(); i++){
        for (int j = 0; j < data.get(i).length; j++){
            printWriter.print("Token  " + data.get(i)[j] + "\n");
        }
    }
    response.sendRedirect("script.js");
    response.getWriter().write(data.toString());
}
Within my javascript file, once the page is loaded and everything is rendered it will fire this off:
$(window).on('load', function() {
$.get("TeacherServlet", function(response) {
    console.log(response);
});
});
I am trying to pass the data that I have in my servlet back to javascript so that I can do other things to the data using Jquery. However I want this data to be passed back as a JSON format.
Please can someone help me do that. Thanks in advance :)
 
     
    