Announcement Announcement Module
Collapse
No announcement yet.
${...} resolution in jsp Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • ${...} resolution in jsp

    Hi all,

    I have a very simple web application in Spring. So far I have a single controller that adds a string to the model map and resolves to a jsp. I have no problem extracting the information from the response object.

    My problem is that the form ${message} doesn't work, where <%= request.getAttribute("message") %> does. Has anyone had a similar experience?

    controller method:
    Code:
    public ModelAndView handleRequest&#40;
    		HttpServletRequest request,
    		HttpServletResponse response&#41;
    		throws ServletException, IOException &#123;
    		
    		return new ModelAndView&#40;"/WEB-INF/jsp/test.jsp", "message", "hi there!"&#41;;
    	&#125;
    test.jsp:
    <html>
    <body>
    ${message} / <%= request.getAttribute("message") %>
    </body>
    </html>

    output in browser:
    Test Menu: ${message} / hi there!

    jars in WEB-INF/lib: (from SPRING_HOME/lib & SPRING_HOME/dist)
    commons-logging.jar
    jstl.jar
    spring.jar
    standard.jar

    spring distribution: spring-framework-1.1.5-with-dependencies

  • #2
    A real newbie problem. :?

    The jsp should contain:
    Code:
    <%@ taglib prefix="c" uri="http&#58;//java.sun.com/jstl/core" %>
    
    <html>
    <body>
    <c&#58;out value="$&#123;message&#125;"/> / <%= request.getAttribute&#40;"message"&#41; %>
    </body>
    </html>
    correctly outputs:
    Code:
    hi there! / hi there!

    Comment


    • #3
      It depends on the servlet container you're using. If it's JSP 2.0/Servlet 2.4 (I think those numbers are right) then your first example would work. If it's an earlier version, then you have to do as your second post.

      Comment


      • #4
        cmgharris, thanks for that. I am using the latest version of Tomcat though, which according to the jakarta website http://jakarta.apache.org/tomcat/ should meet the requirements:

        Code:
        Tomcat version 	5.5.9
        Servlet/JSP Spec  	2.4/2.0
        perhaps I am missing a configuration setting somewhere?

        Comment


        • #5
          Yes; not too sure of my ground here, but try

          Code:
          <web-app    xmlns="http&#58;//java.sun.com/xml/ns/j2ee"
                      xmlns&#58;xsi="http&#58;//www.w3.org/2001/XMLSchema-instance"
                      xsi&#58;schemaLocation="http&#58;//java.sun.com/xml/ns/j2ee
                                          http&#58;//java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
                      version="2.4">
          in your web.xml

          Comment


          • #6
            Ah ha! You're onto something here. Yes, my web.xml appears lacking:

            Code:
            <!DOCTYPE web-app PUBLIC
            	"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
            	"http&#58;//java.sun.com/dtd/web-app_2_3.dtd">
            I'll look into it and post the result here.

            Comment


            • #7
              cmgharris

              Hmm. Well your suggestion was consistent with information posted elsewhere (e.g. http://forum.java.sun.com/thread.jspa?threadID=588217). Still no change though unfortunately.

              I'm uncertain as to whether this is a general servlet configuration issue, a Tomcat 5.5 issue, or a Spring issue. I suspect the first case.

              Anyway, here's my web-app.xml - note that I do not include a <!DOCTYPE> tag:
              Code:
              <?xml version="1.0" encoding="ISO-8859-1"?>
              
              <web-app    xmlns="http&#58;//java.sun.com/xml/ns/j2ee"
                          xmlns&#58;xsi="http&#58;//www.w3.org/2001/XMLSchema-instance"
                          xsi&#58;schemaLocation="http&#58;//java.sun.com/xml/ns/j2ee
                                              http&#58;//java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
                          version="2.4">	
              ...
              </web-app>
              If I try and force the use of EL with a <%@ page isELIgnored="false" %> Tomcat throws a org.apache.jasper.JasperException.

              Comment


              • #8
                Ah. I found some useful information here.

                The changes to the web.xml are correct - thanks cmgharris. To fix the problem you need to download a version of the JSTL that is compatible with 2.4 (see above link).

                Comment

                Working...
                X