So, I'm trying to learn some Spring MVC and the first tutorial I try has a model.addAttribute("printme", "From spring");
and in the JSP a ${printme}
.
My controller is simple:
@RequestMapping(value = "index", method = RequestMethod.GET)
public String index(Model modelMap) {
System.out.println("on method");
modelMap.addAttribute("printme", "Hello Spring FROM INDEX !!");
return "index";
}
When I run the code it doesn't work, so I started adding to the JSP.
I wound up with this in the body:
<h1>
${param.printme}
<br />
${printme}
<br />
${requestScope.printme}
<br />
<%=request.getParameter("printme")%>
<br />
<%=request.getAttribute("printme")%>
<br />
<%=pageContext.findAttribute("printme")%>
</h1>
and my output source looks like this:
<h1>
<br />
<br />
Hello Spring FROM INDEX !!
<br />
null
<br />
Hello Spring FROM INDEX !!
<br />
Hello Spring FROM INDEX !!
</h1>
I expected param.printme
to me empty string, as well as null from request.getParameter()
.
Shouldn't ${printme}
search requestScope and find it?
Shouldn't ${printme}
be the same as
${requestScope.printme}
<%=requestScope.getAttribute("printme")%>
, and<%=pageContext.findAttribute("printme")%>
?
What's going on here, why isn't ${printme}
finding the attribute?
I know I can just keep using ${requestScope.printme}
, but it's more verbose, and I want to know why it's acting the way it is.
In case it matters I'm using Tomcat7.0.52, Spring 4.0 xsds, and java ee 3.0 xsds.