I have my controller Servlet creating an object and placing it into a HashMap and I'm forwarding this to my JSP as an attribute, in my JSP I wish to set this HashMap to a variable, how am I able to do this?
See code below:
ControllerServlet
Map<Integer, Post> posts = new HashMap<Integer, Post>();
// Needs refactoring to a DB query
Post p = new Post();
p.setId(1);
p.setTitle("Hello World!");
p.setBody("This is my first blog post!");
p.setAuthor("Jacob Clark");
p.setPublished(new Date());
posts.put(p.getId(), p);
getServletContext().setAttribute("posts", posts);
RequestDispatcher rd = getServletContext().getRequestDispatcher("/WEB-INF/index.jsp");
rd.forward(request, response);
JSP
getServletContext().getAttribute("posts")