I am working on a project which has just one page(index.jsp) and initial load of the page an Ajax request is being sent and JSON data is retrieved. The AJAX call sent to my Servlet and Servlet returns JSON data,and i have only one Servlet. I am trying to send the some data to my JSP page to populate, so This is how i am writing my Servlet......
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out =response.getWriter();
String queryString = request.getQueryString();
ResourceBundle props = ResourceBundle.getBundle("jira");
XmlMerge xmlMerge = new XmlMerge();
String mergeFiles=xmlMerge.getJsonData();
out.println(mergeFiles);
out.close();
//Debug Statement
System.out.println(xmlMerge.getTodo());
// *THIS IS THE WAY I AM SEND DATA TO JSP PAGE.*
request.setAttribute("todo", xmlMerge.getTodo());
request.getRequestDispatcher("/index.jsp").forward(request, response);
}
and in my index.jsp
<%=(String)request.getAttribute("todo")%>
I am trying to output the result.
What is going wrong?