JSTL c:out not showing the variable's value

17,814

Solution 1

This is an E xpression L anguage issue. Your ${} is not being resolved. This can happen for a number of reasons. One, and the most likely, is that your web.xml is declaring Servlet 2.3 and under. You'll have to specify 2.4+. Now, obviously, your Servlet container must also support that higher version.

Solution 2

Change this - the pad a library is bad:

<!--  %@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>-->
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
Share:
17,814
Lluís Suñol
Author by

Lluís Suñol

Updated on June 04, 2022

Comments

  • Lluís Suñol
    Lluís Suñol almost 2 years

    I'm following a tutorial about spring and I'm supposed to set a variable in a controller in order to be printed within the jsp rendering the request. The code is as follows:

    @Controller
    public class HelloController {
    
        @RequestMapping(value="/hello.htm")
        public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse  response) throws ServletException, IOException {
            String now = (new Date()).toString();
            return new ModelAndView("WEB-INF/views/hello.jsp", "now", now);
        }
    }
    

    Then, the hello.jsp code is as follows:

    <%@ page session="true"%>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
    <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
    <html>
        <body>
            <p>Greetings, it is now <c:out value="${now}" /></p>
        </body>
    </html>
    

    I am expected to get an html showing this:

    Greetings, it is now Mon Fri Dec 06 00:39:35 CET 2013
    

    But all I get is:

    Greetings, it is now ${now}
    

    I've checked everything twice (or even more!) but everything seems to be as the tutorial says but there must be something missing, I hope...

    What's wrong with my code?

  • Lluís Suñol
    Lluís Suñol over 10 years
    It worked! I've changed to 2.5, as in the tutorial, and now it parses the expressions. Thank you Sotirios, you hit the nail on the head!! I created the webapp by using the maven's archetype and you get 2.3 version servlet by default.
  • Balaji Krishnan
    Balaji Krishnan about 9 years
    maven 3 still generates web.xml with servlet 2.3