I try to write the simplest application with Spring MVC (like Hello, World!). Like everything I do according to the textbook. But the result is the html page on which $ {<parameter name>} is displayed instead of the model attribute values ​​transferred from the controller. Ie, for example, in the controller I write:

modelAndView.addObject("body", "Have a nice day!"); 

in JSP:

 <!DOCTYPE html> <html> <head> <title>${title}</title> </head> <body> This is the body: ${body} </body> </html> 

As a result, the page is displayed:

This is the body: $ {body}

I almost all the Internet, I can not find a solution. The program enters the controller and returns the required values.

Here is the complete controller code:

 @Controller public class MainController { @RequestMapping(value="/", method = RequestMethod.GET) public ModelAndView main() { ModelAndView modelAndView = new ModelAndView(); modelAndView.addObject("title", "Hello!"); modelAndView.addObject("body", "Have a nice day!"); modelAndView.setViewName("index"); return modelAndView; } } 
  • Let's start with the simple. I don't know which version of servlets you are using. If below 2.4, then at the very top of the view you should have something like this <% @ page contentType = "text / html; charset = UTF-8" language = java "isELIgnored =" false "%> - Alex
  • Thank! Really earned. It remains only to understand what this means, and why it is not written about it in the tutorial :) - Konstantin Romanov
  • I will arrange it as an answer and explain - Alexey
  • Thank! I really used servlets version 2.3: <! DOCTYPE web-app PUBLIC "- // Sun Microsystems, Inc.//DTD Web Application 2.3 // EN" " java.sun.com/dtd/web-app_2_3.dtd "> - Konstantin Romanov

1 answer 1

The servlet version is probably below 2.4. In that case, at the very top of the JSP, you need to add something like

 <%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %> 

The main thing here is isELIgnored="false" which is a direct indication to calculate expressions written in Expression Language (what is placed in the $ {} or # {} constructs). If version 2.4 then ELIgnored is not needed, it defaults to false