Note that there are some explanatory texts on larger screens.

plurals
  1. POSpring MVC: Form Not Submitting
    text
    copied!<p>In my Spring MVC application, the Form Controller is correctly wired and displays the form as intended.</p> <p>But the Submit button does not work. Moreover, the onSubmit() method of the FormController never gets invoked, because my debug print statements are not shown.</p> <p>Instead, when I click Submit, the form re-loads and some of the fields get changed (very strange behavior).</p> <p>I implemented my FormController as usual in Spring MVC:</p> <pre><code>public class RegisterController extends SimpleFormController { public RegisterController() { setCommandClass(Customer.class); setCommandName("customer"); } @Override protected ModelAndView onSubmit(Object command) throws Exception { // never gets run! Customer customer = (Customer) command; System.out.println("TEST. Obtained Customer object: " + customer.toString()); } } </code></pre> <p>My bean wiring for the Dispatcher Servlet is:</p> <pre><code>&lt;bean name="/register.htm" class="techbooks.web.RegisterController" p:formView="register" p:successView="home"/&gt; </code></pre> <p>"register" refers to register.htm(.jsp) and "home" to home.htm(.jsp), both of which exist.</p> <p>JSP:</p> <pre><code>&lt;%@page contentType="text/html" pageEncoding="UTF-8"%&gt; &lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt; &lt;%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %&gt; &lt;%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%&gt; &lt;html&gt; &lt;head&gt; &lt;meta http-equiv="Content-Language" content="en-us" /&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt; &lt;title&gt;TechBooks.com&lt;/title&gt; &lt;link rel="stylesheet" type="text/css" href="css/main.css" /&gt; &lt;/head&gt; &lt;body&gt; &lt;center&gt; &lt;table style="width: 850px" class="style2"&gt; &lt;form:form method="POST" commandName="customer"&gt; &lt;tr&gt; &lt;td&gt;&lt;h1&gt;Register New Customer&lt;/h1&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &lt;table&gt; &lt;tr&gt; &lt;td align="left"&gt;Customer ID:&lt;/td&gt; &lt;td align="left"&gt;&lt;form:input path="customerId"/&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td align="left"&gt;Customer Password:&lt;/td&gt; &lt;td align="left"&gt;&lt;form:password path="customerPassword"/&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td align="left"&gt;Customer First Name:&lt;/td&gt; &lt;td align="left"&gt;&lt;form:input path="customerFirstName"/&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td align="left"&gt;Customer Last Name:&lt;/td&gt; &lt;td align="left"&gt;&lt;form:input path="customerLastName"/&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td align="left"&gt;Customer Address:&lt;/td&gt; &lt;td align="left"&gt;&lt;form:input path="customerAddress"/&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td align="left"&gt;Customer City:&lt;/td&gt; &lt;td align="left"&gt;&lt;form:input path="customerCity"/&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td align="left"&gt;Customer State:&lt;/td&gt; &lt;td align="left"&gt;&lt;form:input path="customerState"/&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td align="left"&gt;Customer Zip Code:&lt;/td&gt; &lt;td align="left"&gt;&lt;form:input path="customerZipCode"/&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td align="left"&gt;Customer Email Address:&lt;/td&gt; &lt;td align="left"&gt;&lt;form:input path="customerEmailAddress"/&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td align="left"&gt;Date Added:&lt;/td&gt; &lt;td align="left"&gt;&lt;form:input path="customerDateAdded" /&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td align="left"&gt;Is Admin?&lt;/td&gt; &lt;td align="left"&gt;&lt;form:checkbox path="customerIsAdmin"/&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td align="left"&gt;&lt;input type="submit" value="Register"/&gt;&lt;br/&gt;&lt;input type="button" value="Cancel"/&gt; &lt;/td&gt; &lt;td align="left"&gt;&amp;nbsp;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/form:form&gt; &lt;/table&gt; &lt;/center&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>Customer bean class:</p> <pre><code>package techbooks.model; import java.io.Serializable; import java.util.Date; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; public class Customer implements Serializable { @Id private String customerId; private String customerPassword; private String customerFirstName; private String customerLastName; private String customerAddress; private String customerCity; private String customerState; private String customerZipCode; private String customerEmailAddress; private Date customerDateAdded; private Boolean customerIsAdmin; /** * @return the customerId */ public String getCustomerId() { return customerId; } /** * @param customerId the customerId to set */ public void setCustomerId(String customerId) { this.customerId = customerId; } /** * @return the customerPassword */ public String getCustomerPassword() { return customerPassword; } /** * @param customerPassword the customerPassword to set */ public void setCustomerPassword(String customerPassword) { this.customerPassword = customerPassword; } /** * @return the customerFirstName */ public String getCustomerFirstName() { return customerFirstName; } /** * @param customerFirstName the customerFirstName to set */ public void setCustomerFirstName(String customerFirstName) { this.customerFirstName = customerFirstName; } /** * @return the customerLastName */ public String getCustomerLastName() { return customerLastName; } /** * @param customerLastName the customerLastName to set */ public void setCustomerLastName(String customerLastName) { this.customerLastName = customerLastName; } /** * @return the customerAddress */ public String getCustomerAddress() { return customerAddress; } /** * @param customerAddress the customerAddress to set */ public void setCustomerAddress(String customerAddress) { this.customerAddress = customerAddress; } /** * @return the customerCity */ public String getCustomerCity() { return customerCity; } /** * @param customerCity the customerCity to set */ public void setCustomerCity(String customerCity) { this.customerCity = customerCity; } /** * @return the customerState */ public String getCustomerState() { return customerState; } /** * @param customerState the customerState to set */ public void setCustomerState(String customerState) { this.customerState = customerState; } /** * @return the customerZipCode */ public String getCustomerZipCode() { return customerZipCode; } /** * @param customerZipCode the customerZipCode to set */ public void setCustomerZipCode(String customerZipCode) { this.customerZipCode = customerZipCode; } /** * @return the customerEmailAddress */ public String getCustomerEmailAddress() { return customerEmailAddress; } /** * @param customerEmailAddress the customerEmailAddress to set */ public void setCustomerEmailAddress(String customerEmailAddress) { this.customerEmailAddress = customerEmailAddress; } /** * @return the customerDateAdded */ public Date getCustomerDateAdded() { return customerDateAdded; } /** * @param customerDateAdded the customerDateAdded to set */ public void setCustomerDateAdded(Date customerDateAdded) { this.customerDateAdded = customerDateAdded; } /** * @return the customerIsAdmin */ public Boolean getCustomerIsAdmin() { return customerIsAdmin; } /** * @param customerIsAdmin the customerIsAdmin to set */ public void setCustomerIsAdmin(Boolean customerIsAdmin) { this.customerIsAdmin = customerIsAdmin; } } </code></pre> <p>As I said, the form never gets submitted, and the onSubmit() of the Controller never executes. Thanks for any ideas</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