Configuring CORS Support in Java Spring Applications
Cross-Origin Resource Sharing (CORS) is managed by setting specific HTTP response headers, primarily Access-Control-Allow-Origin, which dictates which external domains are permitted to access the resource. When a browser blocks a request due to CORS policy, the error typically resembles:
Access to XMLHttpRequest has been blocked by CORS policy: ...
Posted on Sat, 09 May 2026 13:12:34 +0000 by rageh
Implementing Cross-Origin Resource Sharing (CORS) in Spring MVC
Introduction to CORS
When discussing AJAX cross-domain requests, many developers first think of JSONP. JSONP has been widely used for years, but it has significant limitations. It works by injecting a <script> tag into the page to execute remote JavaScript, which can lead to XSS vulnerabilities if the source is compromised. Additionally, ...
Posted on Sat, 09 May 2026 06:27:51 +0000 by darkhappy
Implementing File Upload in Spring MVC Applications
Temporary Directory Setup
Before implementing file upload, configure the temporary directory where uploaded files are stored during processing.
Option 1: JVM parameter
mkdir -p /app/tmp
-Djava.io.tmpdir=/app/tmp
Option 2: Spring Boot configuration
spring:
servlet:
multipart:
location: /app/tmp
max-file-size: 500MB
max-r ...
Posted on Sat, 09 May 2026 01:09:20 +0000 by The Cat
Essential Spring MVC Annotations for Web Development
@Controller
Applied at the class level, @Controller marks a class as a Spring MVC controller and registers it as a Spring bean. The DispatcherServlet automatically detects such classes and routes incoming HTTP requests to methods annotated with @RequestMapping. This annotation is specifically intended for web controllers—use @Component or other ...
Posted on Fri, 08 May 2026 21:44:59 +0000 by weiwei
Spring MVC: Mappers, Adapters, and Controllers
Spring MVC's core components—HandlerMapping, HandlerAdapter, and Controller—each have distinct responsibilities.
Responsibilities
HandlerMapping (Mapper): Maps incoming HTTP requests to appropriate handlers based on the request URL. It associates request paths with controller beans.
HandlerAdapter (Adapter): Invokes the actual handler metho ...
Posted on Thu, 07 May 2026 06:42:14 +0000 by goa103
Detailed Guide to Spring MVC JSON Parameter Handling and Common Pitfalls
Recently, I decided to stop using sessions and explore tokens for a more secure and robust approach, while also creating a unified interface for both browsers and mobile apps. I refactored a practice project's frontend to use Ajax entirely, keeping Spring MVC for view controller forwarding. This deepened my understanding of JSON data transmissi ...
Posted on Thu, 07 May 2026 00:45:21 +0000 by Haktar