Question
For example, i have 3 steps registration that map with "/register" url. Is it possible to have only one RegisterController that can handle all registration's steps form submit?
Proposed Solution:
Spring 3 - Spring-mvc controller using servlet mapping to your controller. Using the mapping in your url request you will always go to the same controller.
You can create a servlet & servlet mapping that maps to your controller through the spring DispatcherServlet.
Create a servlet & servlet mapping to handle your requests.
Web.XML
<servlet>
<description>
</description>
<display-name>TestServ</display-name>
<servlet-name>main</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>test</servlet-name>
<url-pattern>/test/*</url-pattern>
</servlet-mapping>
Create a spring config file associated to the servlet.
In this case since the name of my servlet is test, it will be test-servlet.xml file that goes into your WEB-INF folder at the root.
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<bean name="/registration/*" class="register.ResgisterController"/>
Create your controller class to map your requests.
package registration;
import java.util.ArrayList;
import java.util.List;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import registration.User;
@Controller
public final class RegistrationController {
public RosterController() {
}
//Spring lets you You can access your spring mvc model from the controller automatically
@RequestMapping
public void list(Model model) {
//do something
}
//Extract a registration id from the request and you can use in your model
@RequestMapping
public void member(@RequestParam("registrationId") Integer id, Model model) {
//do something
}
}