title: Spring MVC basic example using JSP and JSTL as View not working
body: <p>As with many a new person to Spring MVC I am having difficulty getting over that first hurdle. In my case the current hurdle appears to be related to JSTL fmt taglib not formatting my dates properly <b><em>or</em></b> it is being passed a string literal by the value attribute of the fmt tag . I have a simple Maven project which I am using to work out the kinks in my knowledge. The following code snippets are from my WelcomeController, web-servlet.xml, web.xml and welcome.jsp. <br> </p>
  
  <p>WelcomeController.java</p>
  
  <pre><code>    @Controller
      @RequestMapping(value="/")
      class WelcomeController {  
  
          @RequestMapping(method=RequestMethod.GET) 
          public String welcome(Model model) {
              Date today = new Date();
              System.out.println("Controller being called");
              model.addAttribute("today", today);
              System.out.println(model.containsAttribute("today"));
              return "welcome";
         }
      }
  </code></pre>
  
  <p>web-servlet.xml</p>
  
  <pre><code>   &lt;?xml version="1.0" encoding="UTF-8"?&gt;
     &lt;beans&gt; &lt;!-- bean namespaces ommitted for space sake --&gt;
  
          &lt;context:component-scan base-package="org.opel.eros.web"/&gt;
  
          &lt;bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping"/&gt;
  
          &lt;bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"/&gt;
  
          &lt;context:property-placeholder location="classpath:META-INF/properties/web-config.properties"/&gt;
  
          &lt;mvc:annotation-driven/&gt;
  
          &lt;bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;
              &lt;property name="prefix" value="${config.prefix}"/&gt;
              &lt;property name="suffix" value="${config.suffix}"&gt;&lt;/property&gt;
          &lt;/bean&gt;
  </code></pre>
  
  <p></p>
  
  <p>web.xml</p>
  
  <pre><code>   &lt;web-app&gt;
         &lt;servlet&gt;
              &lt;servlet-name&gt;eros&lt;/servlet-name&gt;
              &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt;
              &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
         &lt;/servlet&gt;
  
         &lt;servlet-mapping&gt;
             &lt;servlet-name&gt;eros&lt;/servlet-name&gt;
             &lt;url-pattern&gt;/&lt;/url-pattern&gt;
         &lt;/servlet-mapping&gt;
     &lt;/web-app&gt;
  </code></pre>
  
  <p>And finally welcome.jsp</p>
  
  <pre><code>   &lt;%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%&gt;
     &lt;html&gt;
     &lt;head&gt;&lt;/head&gt;
     &lt;body&gt;
         &lt;fmt:formatDate value="${today}" pattern="yyyy-MM-dd"/&gt;
     &lt;/body&gt;
     &lt;/html&gt;
  </code></pre>
  
  <p>Doesn't get much simpler I know, but an exception is thrown when I enter the url <code>http://localhost:9990/XYZ/</code>, this is the exception: PWC6338: Cannot convert "${today}" for the attribute value of the bean java.util.Date</p>
  
  <p>That seems to me to be an error where the formateDate is being passed the String literal "${today}", which will obviously throw an exception. The example I am using to help (from Spring Reciepes: A problem Solution Approach) states that to access model attributes you use the syntax specified in the fmt tag above. </p>
  
  <p>Basically I am looking for a solution and a reason why this is happening ( I do realise it is probably something really simple <b>and stupid</b> on my part =]). Thanks for any help in advance, much appreciated.</p>