Note that there are some explanatory texts on larger screens.

plurals
  1. POSpring MVC not showing result in jsp
    text
    copied!<p>I am new for Spring Framework. In my POC I am not getting the model value in jsp. below is my code My Controller is </p> <pre><code>@Controller public final class ContactController { @Autowired private Validator validator; public void setValidator(Validator validator) { this.validator = validator; } @RequestMapping(value = "/form", method = RequestMethod.GET) public String get(ModelMap model) { // Because we're not specifying a logical view name, the // DispatcherServlet's DefaultRequestToViewNameTranslator kicks in. UserMessage Message = new UserMessage(); System.out.println("Hello Get Method"); model.addAttribute("userMessage", Message); return "form"; } @RequestMapping(value = "/form", method = RequestMethod.POST) public String post(@ModelAttribute("userMessage") UserMessage userMsg, BindingResult result, Model model) { validator.validate(userMsg, result); System.out.println(userMsg.getName()); model.addAttribute("userMsg",userMsg); if (result.hasErrors()) { return "form"; } // Use the redirect-after-post pattern to reduce double-submits. return "thanks"; } </code></pre> <p>My jsp form is as below</p> <pre><code>&lt;form:form modelAttribute="userMessage"&gt; &lt;div class="form-item"&gt; &lt;div class="form-label"&gt;Your name:&lt;/div&gt; &lt;form:input path="name" size="40" cssErrorClass="form-error-field"/&gt; &lt;div class="form-error-message"&gt;&lt;form:errors path="name"/&gt;&lt;/div&gt; &lt;/div&gt; &lt;div class="form-item"&gt; &lt;div class="form-label"&gt;Your e-mail address:&lt;/div&gt; &lt;form:input path="email" size="40" cssErrorClass="form-error-field"/&gt; &lt;div class="form-error-message"&gt;&lt;form:errors path="email"/&gt;&lt;/div&gt; &lt;/div&gt; &lt;div class="form-item"&gt; &lt;div class="form-label"&gt;Your message:&lt;/div&gt; &lt;form:textarea path="text" rows="12" cols="60" cssErrorClass="form-error-field"/&gt; &lt;div class="form-error-message"&gt;&lt;form:errors path="text"/&gt;&lt;/div&gt; &lt;/div&gt; &lt;div class="form-item"&gt; &lt;input type="submit" value="Submit" /&gt; &lt;/div&gt; &lt;/form:form&gt; </code></pre> <p>Configuration file as below</p> <pre><code>&lt;bean id="configurationLoader" class="org.springmodules.validation.bean.conf.loader.annotation.AnnotationBeanValidationConfigurationLoader"/&gt; &lt;bean id="validator" class="org.springmodules.validation.bean.BeanValidator" p:configurationLoader-ref="configurationLoader"/&gt; &lt;!-- Load messages --&gt; &lt;bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource" p:basenames="errors"/&gt; &lt;!-- Discover POJO @Components --&gt; &lt;!-- These automatically register an AutowiredAnnotationBeanPostProcessor --&gt; &lt;context:component-scan base-package="contact"/&gt; &lt;!-- Map logical view names to physical views --&gt; &lt;bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" p:prefix="/WEB-INF/jsp/" p:suffix=".jsp"/&gt; </code></pre> <p>after filling the form I want the command Object details back in in jsp page so I write as below (thanks.jsp)</p> <pre><code>&lt;%@ page import="contact.UserMessage" %&gt; &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head&gt; &lt;title&gt;Thank You&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;h1&gt;Thank You&lt;/h1&gt; Welcome &lt;%= request.getParameter("name") %&gt; Name is ${userMsg.name} &lt;/body&gt; &lt;/html&gt; </code></pre> <p>request.getParameter("name") is giving correct result but ${userMsg.name} is printing as it is why?</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