The Model value of spring mvc EL ModelAndView is not displayed in jsp.

Source: Internet
Author: User

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>
//...

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.