Using Spring MVC
Using the Web Tier Java SDK
Using Spring MVC (back to all tutorials)
Many web applications leverage the Model-View-Controller (MVC) architecture to promote modularity, testability, and maintainability. The popular Spring Framework supports this architecture and can be used in conjunction with the Veriplace API to build large, maintainable applications.
-
Step 1: Writing PageController.java
The SDK supports adding location to any common Spring controller using an interceptor. The interceptor itself is declared in your application's Spring configuration; the controller can derive from any Spring base class:
The VeriplaceState.getFromRequest() method provides access to the request's VeriplaceState and any data, including location, obtained from Veriplace.
-
Step 2: Writing page.jsp
As with the Servlet example above, PageController.java uses a JSP view:
-
Step 3: Configuring web.xml
Spring-based applications are typically configured using Spring bean declarations. As such, your application's web.xml file only needs to declare the Spring dispatcher servlet:
-
Step 4: Configuring dispatcher-servlet.xml
The Spring dispatcher servlet will read its configuration from dispatcher-servlet.xml. This configuration file needs to contain all of the same information required by the JSP and Servlet examples:
The PropertiesFactoryBean loads your application's OAuth credentials. These are passed to an instance of com.veriplace.web.Veriplace, which manages all application state related to Veriplace.
The statusViewResolver defines waiting and error views.
The com.veriplace.web.spring.LocationDiscoveryInterceptor enforce that Veriplace API calls have been made before control is passed to your controller.
The SimpleHandlerMapping maps your controller to a specific URL.
-
Step 5: Done
You're now ready to deploy a Spring MVC-based web application using the Veriplace API.