Problem:
During spring mvc development, model addAttribute is often displayed in jsp through EL, for example, $ {msg },
However, sometimes the final display of jsp is $ {msg}, rather than the value assigned by msg.
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" %>
$ {Msg}
Solution:
The reason is that the old JSP 1.2 statement.
1. JSPs 1.2
If you use the DTD of jsp1.2
Web. xml
"-// Sun Microsystems, Inc. // DTD Web Application 2.3 // EN"
Http://java.sun.com/dtd/web-app_2_3.dtd>
//...
EL is disabled by default... Must be opened manually. <% @ Page isELIgnored = "false" %>
<% @ Taglib prefix = "c" uri = "http://java.sun.com/jsp/jstl/core" %>
<% @ Page isELIgnored = "false" %>
$ {Msg}
2. JSPs 2.0
JSP2.0 supports EL by default, so jsp2.0 can be directly used if declared.
Web. xml
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>
//...