Note that there are some explanatory texts on larger screens.

plurals
  1. POForm values not getting displayed on POST in spring-java-mvc
    primarykey
    data
    text
    <p>I created a project using <strong>SpringTemplateProject</strong> and using hibernate in that.</p> <p>I created a form and on post the values are getting inserted in database, but the problem is I am not able to display those values on POST.</p> <p>Here is the code:</p> <p>//Controller</p> <pre><code>package com.projects.data; import java.util.Locale; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.ui.ModelMap; import org.springframework.validation.BindingResult; import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import com.projects.data.*; @Controller public class HomeController { private static final Logger logger = LoggerFactory.getLogger(HomeController.class); @Autowired ServiceImpl service; @RequestMapping(value = "/", method = RequestMethod.GET) public ModelAndView customer() { return new ModelAndView("home", "command", new Customer()); } @RequestMapping(value = "/customer", method = RequestMethod.POST) public String addCustomer(@ModelAttribute("customer") Customer customer,ModelMap model) { model.addAttribute("custid",customer.getCustId()); model.addAttribute("name", customer.getName()); model.addAttribute("age", customer.getAge()); service.addCustomer(customer); return "customer/customer"; } } </code></pre> <p>Home.jsp</p> <pre><code>&lt;%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %&gt; &lt;%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%&gt; &lt;%@ page session="false" %&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;Home&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;spring:url var="customer" value="/customer"/&gt; &lt;form:form action="${customer}" method="post" modelAttribute="customer"&gt; &lt;form:label path="custid"&gt;Id:&lt;/form:label&gt; &lt;form:input path="custid"/&gt; &lt;br&gt; &lt;form:label path="name"&gt;Name:&lt;/form:label&gt; &lt;form:input path="name"/&gt; &lt;br&gt; &lt;form:label path="age"&gt;Age:&lt;/form:label&gt; &lt;form:input path="age"/&gt; &lt;br&gt; &lt;input type="submit" value="Save"/&gt; &lt;/form:form&gt; &lt;/html&gt; </code></pre> <p>customer.jsp</p> <pre><code>&lt;%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%&gt; &lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt; &lt;html&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"&gt; &lt;title&gt;Submitted Information&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;h2&gt;Submitted Information&lt;/h2&gt; &lt;table&gt; &lt;tr&gt; &lt;td&gt;Customer id&lt;/td&gt; &lt;td&gt;${custid}&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Name&lt;/td&gt; &lt;td&gt;${name}&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Age&lt;/td&gt; &lt;td&gt;${age}&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>Data is getting inserted in the database, but it is not getting displayed. Please help me resolve this. Thanks.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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