Spring MVC SimpleUrlHandlerMapping example

In Spring MVC application, the SimpleUrlHandlerMapping is the most flexible handler mapping class, which allow developer to specify the mapping of URL pattern and handlers explicitly. The SimpleUrlHandlerMapping can be declared in two ways. 1. Method 1 – prop key The property keys are the URL patterns while the property values are the handler IDs …

Read more

Spring MVC ControllerClassNameHandlerMapping example

In Spring MVC, ControllerClassNameHandlerMapping use convention to map requested URL to Controller (convention over configuration). It takes the Class name, remove the ‘Controller’ suffix if exists and return the remaining text, lower-cased and with a leading “/”. See following few examples to demonstrate the use of this ControllerClassNameHandlerMapping class. 1. Before and After By default, …

Read more

Spring MVC BeanNameUrlHandlerMapping example

In Spring MVC, BeanNameUrlHandlerMapping is the default handler mapping mechanism, which maps URL requests to the name of the beans. For example, <beans …> <bean class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping"/> <bean name="/welcome.htm" class="com.mkyong.common.controller.WelcomeController" /> <bean name="/streetName.htm" class="com.mkyong.common.controller.StreetNameController" /> <bean name="/process*.htm" class="com.mkyong.common.controller.ProcessController" /> </beans> In above example, If URI pattern /welcome.htm is requested, DispatcherServlet will forward the request to the …

Read more

Spring MVC hello world example (Maven and Thymeleaf)

This tutorial shows you how to create a Spring Web MVC application with the Thymeleaf template. Technologies and tools used: Java 11 Spring 5.2.22.RELEASE Thymeleaf 3.0.15.RELEASE Embedded Jetty Server 9.4.45.v20220203 Servlet API 4.0.4 Bootstrap 5.2.0 (webjars) IntelliJ IDEA Maven 3.8.6 Spring Test 5.2.22.RELEASE Hamcrest 2.2 JUnit 5.9 Table of contents: 1. Spring Web MVC Basic …

Read more

ModelAndView’s model value is not displayed in JSP via EL

Problem In Spring MVC development, developer try to set a value into a model, and display the value in JSP via EL, e.g ${msg}, but it just outputs the result as it is – ${msg}, not the “value” stored in the model. The EL is just not working in JSP, why? Spring’s Controller import javax.servlet.http.HttpServletRequest; …

Read more