Big Data and Hadoop Training @$80 or Rs. 6,000 only - valid till Oct 17th Apply Now!

mvc:default-servlet-handler

Ads
 

mvc:default-servlet-handler

In this section, you will learn about configuring tag using Java config or XML Namespace.

In this section, you will learn about configuring tag using Java config or XML Namespace.

mvc:default-servlet-handler

In this section, you will learn about configuring <mvc:default-servlet-handler> tag using using Java config or XML Namespace.

The <mvc:default-servlet-handler> tag configures a handler for processing static resources by forwarding static resource requests to the default Servlet of the Servlet container.

The default configuration for this in XML is :

<mvc:default-servlet-handler/>

You can do the same default configuration using MVC Java config as follows :

@Configuration
@EnableWebMvc
public class MyWebAppConfig extends WebMvcConfigurerAdapter {
	
	@Override
	public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
		configurer.enable();
	}

}

At startup, DefaultServletHttpRequestHandler try to auto-detect the container's default Servlet by utilizing a list of known names. But if it can fails due to unknown Servlet container is used or default Servlet has been custom configured with a different name. In this case you need to provide the name of the default Servlet explicitly. You can do this as shown below :

@Configuration
@EnableWebMvc
public class MyWebAppConfig extends WebMvcConfigurerAdapter {
	
	@Override
	public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
		configurer.enable("myDefaultServlet");
	}

}

You can do the same using XML configuration as follows :

<mvc:default-servlet-handler default-servlet-name="myDefaultServlet"/>

Ads

Ads