Home Spring Spring3.2 mvc:default-servlet-handler
Questions:Ask|Latest


 
 

Share on Google+Share on Google+

mvc:default-servlet-handler

Advertisement
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"/>

Advertisements

Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: March 21, 2013

Ask Questions?    Discuss: mvc:default-servlet-handler  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
DMCA.com