title: Redirect the form result on the same form page in the form of table using Spring mvc
body: <p>I am new to spring and I have been given a task to do. I have created a simple registration form for employee using spring mvc and its result is getting displayed on another jsp page but I want the result to be displayed on the same jsp page where I have filled the form and the result should be in tabular form too.</p>
  
  <p>I tried forward and redirect options also but I am not getting to the result.</p>
  
  <p>Here are my files:</p>
  
  <p>EmployeeFormController.java</p>
  
  <pre><code>public class EmployeeFormController extends SimpleFormController {
  @Override
  protected ModelAndView onSubmit(Object command)
  throws ServletException {
  Employee employee = (Employee) command;  
  
  ModelAndView modelAndView = new ModelAndView("usersuccess");
  modelAndView.addObject("employee", employee);
  return modelAndView;  
  }  
  
  }
  </code></pre>
  
  <p>user.jsp</p>
  
  <pre><code>    &lt;%@ taglib prefix="core" uri="http://java.sun.com/jsp/jstl/core" %&gt;
      &lt;%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %&gt;
      &lt;%@ taglib prefix="spring" uri="/spring"%&gt;
      &lt;%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %&gt;
      &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;Employee Personal Details&lt;/title&gt;
     &lt;/head&gt;
     &lt;body&gt;
     &lt;center&gt; &lt;h3&gt;Employee Personal Details&lt;/h3&gt;
     &lt;br/&gt;
     &lt;form:form commandName="user" method="POST" name="user"&gt;
     &lt;table border="0"&gt;
     &lt;tr&gt;
     &lt;td&gt;Name:&lt;/td&gt;
     &lt;td&gt;&lt;form:input path="name"/&gt;&lt;/td&gt;
     &lt;td&gt;&lt;font color="red"&gt;&lt;form:errors path="name"/&gt;&lt;/font&gt;&lt;/td&gt;
     &lt;/tr&gt;
     &lt;tr&gt;
     &lt;td&gt;Email ID:&lt;/td&gt;
     &lt;td&gt;&lt;form:input path="emailid"/&gt;&lt;/td&gt;
     &lt;td&gt;&lt;font color="red"&gt;&lt;form:errors path="emailid"/&gt;&lt;/font&gt;&lt;/td&gt;
      &lt;/tr&gt;
    &lt;tr&gt;
   &lt;td&gt;Date of birth:&lt;/td&gt;
   &lt;td&gt;&lt;form:input path="dob"/&gt;&lt;/td&gt;
  &lt;td&gt;&lt;font color="red"&gt;&lt;form:errors path="dob"/&gt;&lt;/font&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;Qualification:&lt;/td&gt;
  &lt;td&gt;&lt;form:input path="qualification"/&gt;&lt;/td&gt;
  &lt;td&gt;&lt;font color="red"&gt;&lt;form:errors path="qualification"/&gt;&lt;/font&gt;&lt;/td&gt;&lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;Contact Number:&lt;/td&gt;
  &lt;td&gt;&lt;form:input path="contact"/&gt;&lt;/td&gt;
  &lt;td&gt;&lt;font color="red"&gt;&lt;form:errors path="contact"/&gt;&lt;/font&gt;&lt;/td&gt;
  &lt;/tr&gt; 
  &lt;tr&gt;
  &lt;td&gt;Address:&lt;/td&gt;
  &lt;td&gt;&lt;form:input path="address"/&gt;&lt;/td&gt;
  &lt;td&gt;&lt;font color="red"&gt;&lt;form:errors path="address"/&gt;&lt;/font&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt; 
  &lt;td colspan="3" align="center"&gt;&lt;input type="submit" value="Save"/&gt;&lt;/td&gt; 
  &lt;/tr&gt;
  &lt;/table&gt;
  &lt;/form:form&gt;
  &lt;/center&gt; 
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>usersuccess.jsp</p>
  
  <pre><code>&lt;table border = 2&gt;
  &lt;tr&gt;
  &lt;td colspan="2" align="center"&gt;&lt;font size="5"&gt;Employee Information&lt;/font&gt;&lt;/td&gt; 
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;Name:&lt;/td&gt;
  &lt;td&gt;&lt;core:out value="${employee.name}"/&gt;&lt;/td&gt; 
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;Email ID:&lt;/td&gt;
  &lt;td&gt;&lt;core:out value="${employee.emailid}"/&gt;&lt;/td&gt; 
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;Date Of Birth:&lt;/td&gt;
  &lt;td&gt;&lt;core:out value="${employee.dob}"/&gt;&lt;/td&gt; 
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;Qualification:&lt;/td&gt;
  &lt;td&gt;&lt;core:out value="${employee.qualification}"/&gt;&lt;/td&gt; 
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;Contact Number:&lt;/td&gt;
  &lt;td&gt;&lt;core:out value="${employee.contact}"/&gt;&lt;/td&gt; 
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;Address:&lt;/td&gt;
  &lt;td&gt;&lt;core:out value="${employee.address}"/&gt;&lt;/td&gt; 
  &lt;/tr&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>dispatcher-servlet.xml</p>
  
  <pre><code>&lt;bean id="viewResolver"
  class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;
  &lt;property name="prefix"&gt;
  &lt;value&gt;/WEB-INF/jsp/&lt;/value&gt;
  &lt;/property&gt;
  &lt;property name="suffix"&gt;
  &lt;value&gt;.jsp&lt;/value&gt;
  &lt;/property&gt;
  &lt;/bean&gt;
  &lt;bean id="userController" class="com.web.EmployeeFormController"&gt;
  &lt;property name="sessionForm"&gt;&lt;value&gt;false&lt;/value&gt;&lt;/property&gt;
  &lt;property name="commandName"&gt;&lt;value&gt;user&lt;/value&gt;&lt;/property&gt;
  &lt;property name="commandClass"&gt;&lt;value&gt;com.web.Employee&lt;/value&gt;&lt;/property&gt;
  &lt;property name="formView"&gt;&lt;value&gt;user&lt;/value&gt;&lt;/property&gt;
  &lt;property name="successView"&gt;&lt;value&gt;usersuccess&lt;/value&gt;&lt;/property&gt;
  &lt;/bean&gt;
  </code></pre>