Search code examples
javaspringspring-mvcjsptomcat9

JSP not printing the object correctly


I started learning Spring MVC and created a controller, added a dummy object in ModelAndView:

 modelAndView.addObject("pageContext", pageContext);

Tried to access it in JSP like this:

<div>${pageContext}</div>

But, it's printing an output like:

org.apache.jasper.runtime.PageContextImpl@3085ff7b

Shouldn't it print the exact object output? Using tomcat 9 and jdk8.

Could anyone please point out what might be missing?


Solution

  • pageContext is the name of an implicit JSP object. Try naming something else the object you insert in the model.

    modelAndView.addObject("someObject", theObject );