Nearby lessons

23 of 35

Spring - SimpleFormController and Wizard Forms

📌 What You Will Learn
  • Build a single-page form with SimpleFormController, including its success view
  • Split one form across several pages with AbstractWizardFormController
  • Configure formView, successView and the wizard's page list in ds-servlet.xml

The two form controllers Spring MVC gives you: SimpleFormController for a single-page form and AbstractWizardFormController for a multi-page wizard that carries one command object across several screens. Both examples are complete — every JSP, the controller, the bean and both XML files.

SimpleFormController — index.jsp

This controller class is able to support the Command classes inorder to store form data in Command class objects when we submit user forms.

It was introduced in Spring2.5 version as "org.springframework.web.servlet.mvc.SimpleFormController" and it was deprecated in SPring3.x version and it was removed in spring4.x version. It is best option for Data Validations in Spring WEB MVC Framework, it will render the same page automatically when validation errors are identified and it will forward to successView page when no Validation messages are identified.

If we want to use this controller class then we have to declare an user defined class and it must be extended from SimpleFormController class and we must implement either of the following methods.

protected ModelAndView onSubmit(Object command) throws Exception

protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindingExceptin exception) throws Exception

onSubmit(--) method will take the application logic which we want to execute by submitting form from client.

If we want to use this Controller class, we must provide the the following properties in Controller class configuration.

  • formView: it will take form name to get User form.
  • commandName: it will take logical name to the command class.
  • commandClass: It will take fully qualified name of the command class.
  • sessionForm: to keep Command Object in session scope inorder to reuse command

object.

In case of SimpleFormController, if we want to provide data to the GUI components like checkboxes, radio buttons, Select boxes,..... in user forms from Controller class then we have to override the following method from SimpleFormController class.

public Map referencedData(HttpServletRequest request)throws Exception

Example:

Example01
JCode Cell
1 
2<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
3pageEncoding="ISO-8859-1"%>
4<!DOCTYPE html>
5<html>
6<head>
7<meta charset="ISO-8859-1">
8<title>Insert title here</title>
9</head>
10<body>
11<jsp:forward page="reg"></jsp:forward>
12</body>
13</html>
14

SimpleFormController — registrationform.jsp

Example02
JCode Cell
1 
2<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
3pageEncoding="ISO-8859-1"%>
4<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
5<!DOCTYPE html>
6<html>
7<head>
8<meta charset="ISO-8859-1">
9<title>Insert title here</title>
10</head>
11<body>
12<h2 style="color: red" align="center">Durga Software Solutions</h2>
13<h3 style="color: blue" align="center">User Registration Page</h3>
14<form:form method="POST" action="reg" commandName="user">
15<center>
16<table style="background: lightyellow;">
17<tr>
18<td>User Name</td>
19<td><form:input path="uname" size="20" value="User Name"/></td>
20</tr>
21<tr>
22<td>Password</td>
23<td><form:password path="upwd" value="abc123" showPassword="true"/></td>
24</tr>
25<tr>
26<td>R U Married?</td>
27<td><form:checkbox path="maritalStatus1"/></td>
28</tr>
29<tr>
30<td>R U Single?</td>
31<td><form:checkbox path="maritalStatus2" value="Single"/></td>
32</tr>
33<tr>
34<td>User Qualifications</td>
35<td><form:checkboxes items="${qual_List}" path="uqual" /></td>
36</tr>
37<tr>
38<td>User Gender</td>
39<td>
40<form:radiobutton path="ugender" value="Male"/>Male
41<form:radiobutton path="ugender" value="Female"/>Female
42</td>
43</tr>
44<tr>
45<td>User Work Location</td>
46<td>
47<form:radiobuttons path="uworkLocation" items="${uworkLocation}"/>
48</td>
49</tr>
50<tr>
51<td>User Skill Set</td>
52<td>
53<form:select path="uskillSet" multiple="true">
54 <form:option value="C">C</form:option>
55 <form:option value="C++">C++</form:option>
56 <form:option value="Java">Java</form:option>
57 <form:option value=".Net">.Net</form:option>
58 <form:option value="Oracle">Oracle</form:option>
59</form:select>
60</td>
61</tr>
62<tr>
63<td>User Hobbies</td>
64<td><form:select path="uhobbies" items="${uhobbies}" multiple="true"/></td>
65</tr>
66<tr>
67<td>User Profession</td>
68<td>
69<form:select path="uprofession" multiple="false">
70 <form:options items="${uprofession}"/>
71</form:select>
72</td>
73</tr>
74<tr>
75<td>User Address</td>
76<td>
77<form:textarea path="uaddr"/>
78</td>
79</tr>
80<tr>
81<td><input type="submit" value="Registration"/></td>
82</tr>
83</table>
84</center>
85</form:form>
86</body>
87</html>
88

SimpleFormController — status.jsp

Example03
JCode Cell
1 
2<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
3pageEncoding="ISO-8859-1"%>
4<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
5<!DOCTYPE html>
6<html>
7<head>
8<meta charset="ISO-8859-1">
9<title>Insert title here</title>
10</head>
11<body>
12<h2 style="color: red" align="center">Durga Software Solutions</h2>
13<h3 style="color: green" align="center">User Registration Status </h3>
14<center>
15<table border="1" style="background: lightyellow;">
16<tr>
17<td>User Name</td>
18<td>${user.uname}</td>
19</tr>
20<tr>
21<td>User Password</td>
22<td>${user.upwd}</td>
23</tr>
24<tr>
25<td>R U Married?</td>
26<td>${user.maritalStatus1}</td>
27</tr>
28<tr>
29<td>R U Single?</td>
30<td>${user.maritalStatus2}</td>
31</tr>
32<tr>
33<td>User Qualifications</td>
34<td>
35<c:forEach var="qual" items="${user.uqual}">
36 <c:out value="${qual}"/><br>
37</c:forEach>
38</td>
39</tr>
40<tr>
41<td>User Gender</td>
42<td>${user.ugender}</td>
43</tr>
44<tr>
45<td>User Work Location</td>
46<td>${user.uworkLocation}</td>
47</tr>
48<tr>
49<td>User Skill Set</td>
50<td>
51<c:forEach var="skill" items="${user.uskillSet}">
52 <c:out value="${skill}"/><br>
53</c:forEach>
54</td>
55</tr>
56<tr>
57<td>User Hobbies</td>
58<td>
59<c:forEach var="hobbit" items="${user.uhobbies}">
60 <c:out value="${hobbit}"/><br>
61</c:forEach>
62</td>
63</tr>
64<tr>
65<td>User Profession</td>
66<td>${user.uprofession}</td>
67</tr>
68<tr>
69<td>User Address</td>
70<td>${user.uaddr}</td>
71</tr>
72</table>
73</center>
74<h3 align="center">
75<a href="reg">User Registration Form</a>
76</h3>
77 
78</body>
79</html>
80

SimpleFormController — User.java

Example04
JCode Cell
1 
2package com.durgasoft.command;
3 
4import java.io.Serializable;
5 
6public class User implements Serializable{
7private String uname;
8private String upwd;
9private boolean maritalStatus1;
10private String maritalStatus2;
11private String[] uqual;
12private String ugender;
13private String uworkLocation;
14private String uskillSet;
15private String[] uhobbies;
16private String uprofession;
17private String uaddr;
18 
19 
20public String getUname() {
21return uname;
22}
23public void setUname(String uname) {
24this.uname = uname;
25}
26public String getUpwd() {
27return upwd;
28}
29public void setUpwd(String upwd) {
30this.upwd = upwd;
31}
32 
33public void setMaritalStatus1(boolean maritalStatus1) {
34this.maritalStatus1 = maritalStatus1;
35}
36public boolean isMaritalStatus1() {
37return maritalStatus1;
38}
39 
40public void setMaritalStatus2(String maritalStatus2) {
41this.maritalStatus2 = maritalStatus2;
42}
43public String getMaritalStatus2() {
44if(maritalStatus2 == null || maritalStatus2.equals("")) {
45 maritalStatus2 = "Married";
46}
47return maritalStatus2;
48}
49 
50public void setUqual(String[] uqual) {
51this.uqual = uqual;
52}
53public String[] getUqual() {
54return uqual;
55}
56 
57public void setUgender(String ugender) {
58this.ugender = ugender;
59}
60public String getUgender() {
61return ugender;
62}
63 
64public void setUworkLocation(String uworkLocation) {
65this.uworkLocation = uworkLocation;
66}
67public String getUworkLocation() {
68return uworkLocation;
69}
70 
71public void setUskillSet(String uskillSet) {
72this.uskillSet = uskillSet;
73}
74public String getUskillSet() {
75return uskillSet;
76}
77 
78public void setUhobbies(String[] uhobbies) {
79this.uhobbies = uhobbies;
80}
81public String[] getUhobbies() {
82return uhobbies;
83}
84 
85public void setUprofession(String uprofession) {
86this.uprofession = uprofession;
87}
88public String getUprofession() {
89return uprofession;
90}
91 
92public void setUaddr(String uaddr) {
93this.uaddr = uaddr;
94}
95public String getUaddr() {
96return uaddr;
97}
98}
99

SimpleFormController — RegistrationController.java

Example05
JCode Cell
1 
2package com.durgasoft.controller;
3 
4import java.util.ArrayList;
5import java.util.HashMap;
6import java.util.List;
7import java.util.Map;
8 
9import javax.servlet.http.HttpServletRequest;
10import javax.servlet.http.HttpServletResponse;
11 
12import org.springframework.validation.BindException;
13import org.springframework.web.servlet.ModelAndView;
14import org.springframework.web.servlet.mvc.SimpleFormController;
15 
16import com.durgasoft.command.User;
17 
18public class RegistrationController extends SimpleFormController{
19 
20@Override
21protected Map referenceData(HttpServletRequest request) throws Exception {
22Map<String, Object> map = new HashMap<>();
23 
24List<String> qual_List = new ArrayList<>();
25qual_List.add("BSC");
26qual_List.add("BTech");
27qual_List.add("MCA");
28qual_List.add("MTech");
29qual_List.add("PHD");
30map.put("qual_List", qual_List);
31 
32List<String> uworkLocation = new ArrayList<>();
33uworkLocation.add("Hyderabad");
34uworkLocation.add("Chennai");
35uworkLocation.add("Pune");
36uworkLocation.add("Mumbai");
37map.put("uworkLocation", uworkLocation);
38 
39Map<String, String> uhobbies = new HashMap<>();
40uhobbies.put("Playing Cricket", "Playing Cricket");
41uhobbies.put("Listening Music", "Listening Music");
42uhobbies.put("Chatting with Friends", "Chatting with Friends");
43map.put("uhobbies", uhobbies);
44 
45Map<String, String> uprofession = new HashMap<>();
46uprofession.put("Former", "Former");
47uprofession.put("Employee", "Employee");
48uprofession.put("Teacher", "Teacher");
49map.put("uprofession", uprofession);
50 
51return map;
52}
53 
54@Override
55protected ModelAndView onSubmit(Object command) throws Exception {
56User user = (User)command;
57return new ModelAndView("status", "user", user);
58}
59}
60

SimpleFormController — ds-servlet.xml

Example06
JCode Cell
1 
2<?xml version="1.0" encoding="UTF-8"?>
3<beans xmlns="http://www.springframework.org/schema/beans"
4xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5xmlns:p="http://www.springframework.org/schema/p"
6xmlns:context="http://www.springframework.org/schema/context"
7xsi:schemaLocation="
8 http://www.springframework.org/schema/beans
9 http://www.springframework.org/schema/beans/spring-beans.xsd
10 http://www.springframework.org/schema/context
11http://www.springframework.org/schema/context/spring-context.xsd">
12 
13<!--
14<bean name="/registrationpage" class="org.springframework.web.servlet.mvc.ParameterizableViewController">
15<property name="viewName" value="registrationform"/>
16</bean>
17-->
18<bean name="/reg" class="com.durgasoft.controller.RegistrationController">
19<property name="formView" value="registrationform"/>
20<property name="sessionForm" value="true"/>
21<property name="commandName" value="user"/>
22<property name="commandClass" value="com.durgasoft.command.User"/>
23</bean>
24 
25<bean name="handlerMapping" class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping"/>
26 
27<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
28<property name="prefix" value="/WEB-INF/"/>
29<property name="suffix" value=".jsp"/>
30</bean>
31</beans>
32

SimpleFormController — web.xml

Example07
JCode Cell
1 
2<?xml version="1.0" encoding="UTF-8"?>
3<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd" id="WebApp_ID" version="4.0">
4<display-name>app7</display-name>
5<welcome-file-list>
6<welcome-file>index.html</welcome-file>
7<welcome-file>index.htm</welcome-file>
8<welcome-file>index.jsp</welcome-file>
9<welcome-file>default.html</welcome-file>
10<welcome-file>default.htm</welcome-file>
11<welcome-file>default.jsp</welcome-file>
12</welcome-file-list>
13<servlet>
14<servlet-name>ds</servlet-name>
15<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
16<load-on-startup>1</load-on-startup>
17</servlet>
18<servlet-mapping>
19<servlet-name>ds</servlet-name>
20<url-pattern>/</url-pattern>
21</servlet-mapping>
22</web-app>
23

AbstractWizardFormController — index.jsp

In general, In web applications , it is required to display more than one page in order to complete a given task.

In web applications, providing sequence of pages in a single task is called as "Wizard".

IN general, in Web applications, we will use multiple pages to enter user details like general details, qualification details, communication details,....in User registration process, to achieve this we have to use "Wizard".

To support for the Wizards in web applications, Spring Web MVC has provided a predefined controller in the form of "org.springframework.web.servlet.mvc.AbstractWizardFormController".

AbstractWizardFormController allows us to carry the same command object through an entire flow of Web pages in Wizard.

If we want to use AbstractWizardController class in Spring web MVC applications then we have to use the following steps.

  • Prepare multiple web pages with the buttons where names of the buttons must be
  • _finish: Finish the wizard form.
  • _cancel: Cancel the wizard form.
  • _targetx: Move to the target page, where x is the zero-based page index.
  • Prepare Controller class by extending AbstractWizardFormController class and override the following methods.

a)protected ModelAndView processFinish(HttpServletRequest request, HttpServletResponse response, Object command, BindException exception) throws Exception

b)protected ModelAndView processCancel(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) throws Exception

Where processFinish() method will handle Wizard Finish action. Where processCancel() method will handle izard cancel Task.

  • Configure contoller class configuration in Spring configuration file with "pages" property , where "pages" property must be of "list" type, it must include all the pages names in a sequence inorder to open the pages when we click on Next buttons in Wizard.

EX:

<bean name="/reg" class="com.durgasoft.controller.UserController"> <property name="pages"> <list> <value>form1</value> <vale>form2</value> <value>form3</value> </list> </property> </beans>

Example:

Example08
JCode Cell
1 
2<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
3pageEncoding="ISO-8859-1"%>
4<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
5<html>
6<head>
7<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
8<title>Insert title here</title>
9</head>
10<body>
11<br><br><br>
12<jsp:forward page="welcomepage"/>
13</body>
14</html>
15

AbstractWizardFormController — welcomepage.jsp

Example09
JCode Cell
1 
2<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
3pageEncoding="ISO-8859-1"%>
4<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
5<html>
6<head>
7<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
8<title>Insert title here</title>
9</head>
10<body>
11<h1 align="center">
12<a href="reg">User Registration Form</a>
13</h1>
14</body>
15</html>
16

AbstractWizardFormController — form1.jsp

Example10
JCode Cell
1 
2<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
3pageEncoding="ISO-8859-1"%>
4<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
5<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
6<html>
7<head>
8<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
9<title>Insert title here</title>
10</head>
11<body>
12<h2 style="color: red;" align="center">Durga Software Solutions</h2>
13<h3 style="color: blue;" align="center">User Registration Page</h3>
14<form:form method="POST" commandName="user">
15<center>
16<table>
17<tr>
18<td>First Name</td>
19<td><form:input path="fname"/>
20</tr>
21<tr>
22<td>Last Name</td>
23<td><form:input path="lname"/>
24</tr>
25<tr>
26<td colspan="2">
27<input type="submit" name="_target1" value="Next"/>
28<input type="submit" name="_cancel" value="Cancel"/>
29</td>
30</tr>
31</table>
32</center>
33</form:form>
34</body>
35</html>
36

AbstractWizardFormController — form2.jsp

Example11
JCode Cell
1 
2<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
3pageEncoding="ISO-8859-1"%>
4<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
5<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
6<html>
7<head>
8<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
9<title>Insert title here</title>
10</head>
11<body>
12<h2 style="color: red;" align="center">Durga Software Solutions</h2>
13<h3 style="color: blue;" align="center">User Registration Page</h3>
14<form:form method="POST" commandName="user">
15<center>
16<table>
17<tr>
18<td>User Qualification</td>
19<td><form:input path="uqual"/>
20</tr>
21<tr>
22<td>User Designation</td>
23<td><form:input path="udes"/>
24</tr>
25<tr>
26<td colspan="2">
27<input type="submit" name="_target0" value="Previous"/>
28<input type="submit" name="_target2" value="Next"/>
29<input type="submit" name="_cancel" value="Cancel"/>
30</td>
31</tr>
32</table>
33</center>
34</form:form>
35</body>
36</html>
37

AbstractWizardFormController — form3.jsp

Example12
JCode Cell
1 
2<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
3pageEncoding="ISO-8859-1"%>
4<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
5<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
6<html>
7<head>
8<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
9<title>Insert title here</title>
10</head>
11<body>
12<h2 style="color: red;" align="center">Durga Software Solutions</h2>
13<h3 style="color: blue;" align="center">User Registration Page</h3>
14<form:form method="POST" commandName="user">
15<center>
16<table>
17<tr>
18<td>User Email Id</td>
19<td><form:input path="uemail"/>
20</tr>
21<tr>
22<td>User Mobile No</td>
23<td><form:input path="umobile"/>
24</tr>
25<tr>
26<td colspan="2">
27<input type="submit" name="_target1" value="Previous"/>
28<input type="submit" name="_finish" value="Finish"/>
29<input type="submit" name="_cancel" value="Cancel"/>
30</td>
31</tr>
32</table>
33</center>
34</form:form>
35</body>
36</html>
37

AbstractWizardFormController — userdetails.jsp

Example13
JCode Cell
1 
2<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
3pageEncoding="ISO-8859-1"%>
4<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
5<html>
6<head>
7<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
8<title>Insert title here</title>
9</head>
10<body>
11<br><br><br>
12<h2 style="color: red;" align="center">Durga Software Solutions</h2>
13<h3 style="color: blue;" align="center">User Registration Details</h3>
14<center>
15<table border="1">
16<tr>
17<td>First Name</td>
18<td>${user.fname}</td>
19</tr>
20<tr>
21<td>Last Name</td>
22<td>${user.lname}</td>
23</tr>
24<tr>
25<td>User Qualification</td>
26<td>${user.uqual}</td>
27</tr>
28<tr>
29<td>User Designation</td>
30<td>${user.udes}</td>
31</tr>
32<tr>
33<td>User Email Id</td>
34<td>${user.uemail}</td>
35</tr>
36<tr>
37<td>User Mobile No</td>
38<td>${user.umobile}</td>
39</tr>
40</table>
41<h3 align="center"></h3>
42<a href="welcomepage">Welcome Page</a>
43</center>
44</body>
45</html>
46

AbstractWizardFormController — UserController.java

Example14
JCode Cell
1 
2package com.durgasoft.controller;
3 
4import javax.servlet.http.HttpServletRequest;
5import javax.servlet.http.HttpServletResponse;
6 
7import org.springframework.validation.BindException;
8import org.springframework.web.servlet.ModelAndView;
9import org.springframework.web.servlet.mvc.AbstractWizardFormController;
10 
11import com.durgasoft.command.User;
12 
13public class UserController extends AbstractWizardFormController {
14 
15@Override
16protected ModelAndView processFinish(HttpServletRequest request, HttpServletResponse response, Object command,
17 BindException exception) throws Exception {
18User user = (User)command;
19return new ModelAndView("userdetails", "user", user);
20}
21 
22@Override
23protected ModelAndView processCancel(HttpServletRequest request, HttpServletResponse response, Object command,
24 BindException errors) throws Exception {
25// TODO Auto-generated method stub
26return new ModelAndView("welcomepage");
27}
28 
29 
30}
31

AbstractWizardFormController — User.java

Example15
JCode Cell
1 
2package com.durgasoft.command;
3 
4public class User {
5private String fname;
6private String lname;
7private String uqual;
8private String udes;
9private String uemail;
10private String umobile;
11 
12public String getFname() {
13return fname;
14}
15public void setFname(String fname) {
16this.fname = fname;
17}
18public String getLname() {
19return lname;
20}
21public void setLname(String lname) {
22this.lname = lname;
23}
24public String getUqual() {
25return uqual;
26}
27public void setUqual(String uqual) {
28this.uqual = uqual;
29}
30public String getUdes() {
31return udes;
32}
33public void setUdes(String udes) {
34this.udes = udes;
35}
36public String getUemail() {
37return uemail;
38}
39public void setUemail(String uemail) {
40this.uemail = uemail;
41}
42public String getUmobile() {
43return umobile;
44}
45public void setUmobile(String umobile) {
46this.umobile = umobile;
47}
48 
49 
50}
51

AbstractWizardFormController — ds-servlet.xml

Example16
JCode Cell
1 
2<?xml version="1.0" encoding="UTF-8"?>
3<beans xmlns="http://www.springframework.org/schema/beans"
4xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5xmlns:p="http://www.springframework.org/schema/p"
6xmlns:context="http://www.springframework.org/schema/context"
7xsi:schemaLocation="
8 http://www.springframework.org/schema/beans
9 http://www.springframework.org/schema/beans/spring-beans.xsd
10 http://www.springframework.org/schema/context
11http://www.springframework.org/schema/context/spring-context.xsd">
12<bean name="/welcomepage" class="org.springframework.web.servlet.mvc.ParameterizableViewController">
13<property name="viewName" value="welcomepage"/>
14</bean>
15<bean name="handlerMapping" class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping"/>
16<bean name="/reg" class="com.durgasoft.controller.UserController">
17<property name="pages">
18 <list>
19 <value>form1</value>
20 <value>form2</value>
21 <value>form3</value>
22 </list>
23</property>
24<property name="commandName" value="user"/>
25<property name="commandClass" value="com.durgasoft.command.User"/>
26 
27</bean>
28<bean name="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
29<property name="prefix" value="/WEB-INF/"/>
30<property name="suffix" value=".jsp"/>
31</bean>
32</beans>
33

AbstractWizardFormController — web.xml

Example17
JCode Cell
1 
2<?xml version="1.0" encoding="UTF-8"?>
3<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd" id="WebApp_ID" version="4.0">
4<display-name>abstractwizardcontrollerapp</display-name>
5<welcome-file-list>
6<welcome-file>index.html</welcome-file>
7<welcome-file>index.htm</welcome-file>
8<welcome-file>index.jsp</welcome-file>
9<welcome-file>default.html</welcome-file>
10<welcome-file>default.htm</welcome-file>
11<welcome-file>default.jsp</welcome-file>
12</welcome-file-list>
13<servlet>
14<servlet-name>ds</servlet-name>
15<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
16<load-on-startup>1</load-on-startup>
17</servlet>
18<servlet-mapping>
19<servlet-name>ds</servlet-name>
20<url-pattern>/</url-pattern>
21</servlet-mapping>
22</web-app>
23
📝 Key Takeaways
  • SimpleFormController separates showing the form from handling the submission
  • A wizard keeps one command object alive across pages, so partial input survives navigation
  • Both need their views declared in configuration, not hard-coded in the controller