Online Training Spring Hibernate Training in Delhi R Programming Training Course Big Data and Hadoop Training Java Training

Static Resources Configuration

In this section, you will learn about Static Resources Configuration through MVC Java config and XML Namespace.

Ads

Tutorials   
Spring 3.2 MVC insert and retrieve blob from the database The hidden tag The errors tag net.roseindia.dao net.roseindia.service net.roseindia.model net.roseindia.controller Spring 3.2 MVC Hibernate Example Spring 3.2 MVC, Upload File in a specific folder Spring 3.2 MVC Form Handling The textarea tag The options tag The option tag The select tag The radiobuttons tag The radiobutton tag The checkboxes tag mvc:default-servlet-handler Static Resources Configuration View Controllers Configuration View resolvers Spring 3.2 MVC Hello World Example Content Negotiation Configuration Interceptors Configuration using Java or XML Customizing the MVC Java config or XML Namespace MVC Java Config or the MVC XML Namespace Servlet container initialization through code Support for ETag The checkbox tag Autogenerated logical view name through RequestToViewNameTranslator Modification in conventional ModelAndView ControllerClassNameHandlerMapping class for handling convention mapping The password tag The input tag The form tag Form Tag library configuration Customizing the Default Error Page @ExceptionHandler & @ResponseStatus annotation Multipart support for file upload in Spring MVC Themes and Theme resolvers in Spring MVC Locales in Spring MVC ContentNegotiatingViewResolver Redirecting and forwarding to views Chaining of Multiple view resolvers View Resolving through ViewResolver interface Requests Intercepting through a HandlerInterceptor Defining handler methods using @RequestMapping annotation Spring 3.2 Asynchronous Request Processing @RequestMapping annotation for mapping requests @Controller annotation for defining new controller
Ads

Static Resources Configuration

In this section, you will learn about Static Resources Configuration through MVC Java config and XML Namespace.

Using this alternative, static resource request of a specific pattern (URL pattern) is handled by ResourceHttpRequestHandler which searches the requested resource at the listed resource locations and serve it. This option also gives easy way to serve static resources from locations other than the web application root, including locations on the classpath.

Given below MVC Java config to configure static resources :

@Configuration
@EnableWebMvc
public class MyWebAppConfig extends WebMvcConfigurerAdapter {
	
	@Override
	public void addResourceHandlers(ResourceHandlerRegistry registry) {
		registry.addResourceHandler("/resources/**").addResourceLocations("/public-contents/");
	}

}

In the above configuration, the resource requests having URL pattern /resources/** is served from directory /public-contents/ in the web application root.

You can do the same in MVC XML Namespace as :


<mvc:resources mapping="/resources/**" location="/public-contents/"/>

You can set the expiration period which assures maximum utilization of the web-browser cache and also cut down HTTP requests from browser. You can configure it using MVC Java config as below :

@Configuration
@EnableWebMvc
public class MyWebAppConfig extends WebMvcConfigurerAdapter {

	@Override
	public void addResourceHandlers(ResourceHandlerRegistry registry) {
		registry.addResourceHandler("/resources/**").addResourceLocations("/public-contents/").setCachePeriod(31556926);
	}

}

In the above case, we are setting the expiration period for 1 year. You can do the same in XML as :


<mvc:resources mapping="/resources/**" location="/public-contents/" cache-period="31556926"/>



Advertisements

Ads
Share on Google+Share on Google+

Static Resources Configuration

Posted on: March 21, 2013 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Advertisements

 

Discuss: Static Resources Configuration  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0

Ads

 

Ads