Note that there are some explanatory texts on larger screens.

plurals
  1. POJSPs not displaying objects from model in Spring
    text
    copied!<p>I have what should be an easy issue to solve, but I'm having no luck.</p> <p>In my servlet-servlet.xml file, I have the following beans (in addition to others):</p> <pre><code>&lt;bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver"&gt; &lt;property name="viewClass" value="org.springframework.web.servlet.view.JstlView" /&gt; &lt;property name="prefix" value="/WEB-INF/jsp/" /&gt; &lt;property name="suffix" value=".jsp" /&gt; &lt;/bean&gt; &lt;context:component-scan base-package="com.servlet.web" /&gt; </code></pre> <p>My test controller looks like this:</p> <pre><code>package com.servlet.web; import java.util.Map; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.RequestMapping; @Controller public class TestController { protected final Log log = LogFactory.getLog(getClass()); @RequestMapping("/test") public String methodName(Map&lt;String, Object&gt; map) { map.put("someMessage", "some string here"); return "test"; } } </code></pre> <p>My jsp view looks like this:</p> <pre><code>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"&gt; &lt;head&gt; &lt;meta http-equiv="content-type" content="text/html; charset=utf-8" /&gt; &lt;title&gt;servlet.com&lt;/title&gt; &lt;/head&gt; &lt;body&gt; ${someMessage} &lt;/body&gt; &lt;/html&gt; </code></pre> <p>So, when I view the jsp, I'd expect the value of someMessage (some string here), but I only get the following:</p> <pre><code>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"&gt; &lt;head&gt; &lt;meta http-equiv="content-type" content="text/html; charset=utf-8" /&gt; &lt;title&gt;servlet.com&lt;/title&gt; &lt;/head&gt; &lt;body&gt; ${someMessage} &lt;/body&gt; &lt;/html&gt; </code></pre> <p>When I crank up the logging, I see that my someMessage object is being place in the model:</p> <pre><code>22:21:17,425 DEBUG DispatcherServlet:852 - DispatcherServlet with name 'servlet' determining Last-Modified value for [/servlet/access/test] 22:21:17,426 DEBUG DefaultAnnotationHandlerMapping:183 - Mapping [/test] to handler 'com.servlet.web.TestController@762fef' 22:21:17,426 DEBUG DispatcherServlet:868 - Last-Modified value for [/servlet/access/test] is: -1 22:21:17,426 DEBUG DispatcherServlet:700 - DispatcherServlet with name 'servlet' processing GET request for [/servlet/access/test] 22:21:17,427 DEBUG HandlerMethodInvoker:158 - Invoking request handler method: public java.lang.String com.servlet.web.TestController.methodName(java.util.Map) 22:21:17,427 DEBUG DispatcherServlet:1070 - Rendering view [org.springframework.web.servlet.view.JstlView: name 'test'; URL [/WEB-INF/jsp/test.jsp]] in DispatcherServlet with name 'servlet' 22:21:17,427 DEBUG JstlView:328 - Added model object 'someMessage' of type [java.lang.String] to request in view with name 'test' 22:21:17,428 DEBUG JstlView:237 - Forwarding to resource [/WEB-INF/jsp/test.jsp] in InternalResourceView 'test' 22:21:17,429 DEBUG DispatcherServlet:666 - Successfully completed request </code></pre> <p>Obviously, my view is mapped correctly, but I can't seem to access model objects added to the request in the view. I've done this type of thing with Spring MVC many times in the past, but I must be missing something obvious here. Any ideas? Thanks.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload