Problem:
Spring MVC development process, often give model AddAttribute, and then through the El in JSP display, such as ${msg},
However, there are times when the JSP finally shows the ${msg} instead of the MSG assignment.
Spring Controller
Import Javax.servlet.http.HttpServletRequest;
Import Javax.servlet.http.HttpServletResponse;
Import Org.springframework.web.servlet.ModelAndView;
Import Org.springframework.web.servlet.mvc.AbstractController;
public class Abccontroller extends abstractcontroller{
@Override
Protected Modelandview handlerequestinternal (HttpServletRequest request,
HttpServletResponse response) throws Exception {
Modelandview model = new Modelandview ("Helloworldpage");
Model.addobject ("msg", "Hello World");
return model;
}
}
JSP page
<%@ taglib prefix= "C" uri= "Http://java.sun.com/jsp/jstl/core"%>
<body>
${MSG}
</body>
Workaround:
The reason for this is the old JSP 1.2 declaration.
1. JSP 1.2
If you're using the jsp1.2 version of the DTD
Xml
<! DOCTYPE Web-app Public
"-//sun Microsystems, INC.//DTD Web application 2.3//en"
"Http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
//...
</web-app>
El is off by default ... Must be opened manually. <%@ page iselignored= "false"%>
<%@ taglib prefix= "C" uri= "Http://java.sun.com/jsp/jstl/core"%>
<%@ page iselignored= "false"%>
<body>
${MSG}
</body>
2. JSP 2.0
JSP2.0 default is to open the support El, so the declaration of jsp2.0 can be used directly.
Xml
<web-app id= "webapp_id" version= "2.4"
Xmlns= "HTTP://JAVA.SUN.COM/XML/NS/J2EE"
Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"
Xsi:schemalocation= "Http://java.sun.com/xml/ns/j2ee
Http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd ">
//...
</web-app>
The Model value of spring MVC EL Modelandview does not appear in the JSP