Posts

Showing posts with the label Spring-MVC

Spring MVC - How to handle errors from a controller?

Image
In a web application, it is very important to handle errors. Proper error handling would protect the application from several vulnerabilities, including Security Misconfiguration . In this post, you will see how you can handle exceptions that arise out of a Spring MVC based application.

Localization with Spring

Image
Localization enables applications to cater to users of different locations and languages. Spring, as usual, has support for this aspect as well. Before jumping into what Spring has to offer, let's explore what we get from Java itself.

ETags and Browser Cache

Image
Caching resources on the browser is crucial to minimize unnecessary trips to the server and reduce the load on it. This works well for data that is static. But, there are cases where the data changes every once in a while (although less frequently), and you would want the browser to get the latest data without waiting for the cached data to expire. e.g., consider a scenario where a new version of the application is deployed with changes to CSS and javascript, and you want the user to experience these changes without forcing them to refresh their cache manually. One option you might consider is to make these resources non-cacheable and compromise the page performance a bit. Entity tags ( or ETags for short) help you cache such resources, without the performance compromise.

What Is a SessionAttributeStore? When to Use It?

Image
In one of my projects, I had an abstract controller class that simulated the form controller of Spring 1.2 for session forms. Annotations do not accept dynamic parameters. They have to be static. So, in the class, the command object name had to be a constant.

Spring MVC - mvc:annotation-driven - What does it do?

Image
The annotations based MVC was introduced to the framework in Spring 2.5. This model enables the developer to reuse any POJO as a controller and is very flexible with the handler signatures. The old controller hierarchy is deprecated as of Spring 3.0. It would be removed completely from the distribution in one of the future releases.