Most dynamic web pages are composed of template and data. In Spring MVC, data is sent usually from controller to view. How to send data (from controller's point) Usually data is created in controller. The following is some ways to send data. (Not exhaustive explanation. More on RequestMapping handler method) To declare Model as parameter … Continue reading Sending data from controller to view
Tag: spring mvc
About Spring ViewResolver
ViewResolver is very important component of Spring MVC. Without proper understanding, it is difficult to analyze MVC components, especially when taking over other's source code. The following explanations is based on Spring Framework 4.3.18. What is ViewResolver? (org.springframework.web.servlet.ViewResolver) ViewResolver is the translator which converts view name into View object View is the component which renders … Continue reading About Spring ViewResolver
Implementing REST API with Spring MVC
Spring MVC helps to build REST API server with minimum code. The crucial files are as follows. pom.xml (with dependency to spring framework and jackson 2) Spring context xml REST DAO class REST Controller class pom.xml Dependency to Spring framework and jackson2 is required spring context xml (servlet-context.xml) Above context don't have any view resolver. … Continue reading Implementing REST API with Spring MVC
The inner working of DispatcherServlet
The main program of Spring MVC is DispatcherServlet. Most Spring MVC webapp's web.xml is as follows. <?xml version="1.0" encoding="UTF-8"?> <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <!-- The definition of the Root Spring Container shared by all Servlets and Filters --> <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/spring/root-context.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <servlet> <servlet-name>appServlet</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> … Continue reading The inner working of DispatcherServlet