Announcement Announcement Module
Collapse
No announcement yet.
variables not passed via ModelAndView(..) to jsp Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • variables not passed via ModelAndView(..) to jsp

    Hi All

    Reading the following tutorial, http://static.springframework.org/do...tep/part2.html, I got stuck in the second chapter!

    In my HelloController.java, I make the following call:

    Code:
    .....
    String now = (new Date()).toString();
    logger.info("Returning hello view with " + now);
    return new ModelAndView("WEB-INF/jsp/hello.jsp", "now", now);
    }
    and the hello.jsp looks like
    Code:
    <%@ include file="/WEB-INF/jsp/include.jsp" %>
    
    <html>
      <head><title>Hello :: Spring Application</title></head>
      <body>
        <h1>Hello - Spring Application</h1>
        <p>Greetings, it is now <c:out value="${now}"/></p>
      </body>
    </html>
    and finally the include.jsp looks like
    Code:
    <%@ page session="false"%>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
    <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
    But when I run the code the output is:
    HTML Code:
        <h1>Hello - Spring Application</h1>
        <p>Greetings, it is now ${now}</p>
    for some reason the ${now} is not seen as a variable. Any suggestions what might be the cause of this ?

    If it might help, here are all the libraries I have inside war/WEB_INF/lib
    Code:
    antlrworks.jar		
    commons-logging.jar	
    jstl.jar		
    servlet-api.jar		
    spring.jar
    commons-el.jar		
    jsp-api.jar		
    junit-4.6.jar		
    spring-webmvc.jar	
    standard.jar
    thnx a lot
    LuCa

  • #2
    Make sure your web.xml begins this way:
    Code:
    <web-app
    	version="2.4" 
    	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">

    Comment


    • #3
      wow, thats it, I had
      Code:
      <web-app version="2.5"
               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" >
      I'm just interested, why can this mistake cause the above problem ?

      thanks a lot!!!
      LuCa

      Comment


      • #4
        thnx a lot, that solved the problem, I had
        Code:
        <web-app version="2.5"
                 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" >
        Do you know why this version is so important ?

        cheers
        LuCa

        Comment

        Working...
        X