The Model value of spring MVC EL Modelandview does not appear in the JSP

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.