Day 29 — #100DaysOfJava ☕ What happens when a browser requests a JSP page? Not "it shows HTML." What actually happens. Step by step. Inside the server. --- The JSP Life Cycle has 6 phases. Here is every one of them. Phase 1 — Translation your .jsp file is not Java yet. The server's JSP Container takes your file and converts it into a .java Servlet file. Every JSP tag becomes Java code. Every piece of HTML becomes an out.write() call. You never see this file unless you look inside the server's metadata folder. Phase 2 — Compilation That generated .java file is compiled into a .class bytecode file. Same as any Java program. This is why JSP is fast after the first request — the compilation already happened. Phase 3 — Loading and Instantiation The .class file is loaded onto the server and an object of that Servlet class is created. One object. Created once. Shared across all requests. Phase 4 — Initialization The jspInit() method runs once. This is where you set up resources that every request will share — database connections, configuration values. Runs one time only. Never again unless the server restarts. Phase 5 — Request Handling This is where your users actually get served. For every single request that comes in, _jspService() runs. This is the method that processes dynamic content, reads request parameters, and writes the HTML response. Every request. Every time. Phase 6 — Destroy When the server shuts down or the JSP is no longer needed, jspDestroy() runs. Cleanup happens here — close connections, release resources. Runs once. Then the object is gone. --- The three interview questions this answers: How many phases in JSP life cycle? — Six. Which method handles client requests? — _jspService(). Not doGet(). Not doPost(). The JSP Container calls _jspService() directly — it handles both GET and POST internally. What creates the initial JSP object? — The JSP Container. Not you. You never instantiate a JSP manually. The container controls the entire lifecycle. --- The thing that clicked today — JSP life cycle and Servlet life cycle are almost identical. Servlet: init() → service() → destroy() JSP: jspInit() → _jspService() → jspDestroy() JSP just has two extra steps at the beginning — Translation and Compilation — because your file starts as JSP and needs to become a Servlet first. After that, it IS a Servlet. Running the same lifecycle. The same container managing it. The same object serving every request. JSP is not a different technology from Servlets. It is Servlets with a friendlier way to write HTML. --- One thing most beginners miss — that .class file is cached. The first request to a JSP page is slow. Translation. Compilation. Loading. Instantiation. Initialization. All happening before a single user sees anything. Every request after that? Fast. The object is already loaded. _jspService() just runs. #Java #JSP #Servlets #JSPLifeCycle #BackendDevelopment #WebDevelopment #JavaDeveloper
JSP Life Cycle Explained in 6 Phases
More Relevant Posts
-
🚀 The Full Anatomy of JSP: Directives, Scopes, and Scripting ✔️If you're building Java Web apps, understanding how JSP (JavaServer Pages) handles data is a game-changer. It’s not just about tags it’s about understanding the "Big Three" elements that make your page dynamic. 🛠️ 1. JSP Directives (The Configuration) Directives are the "Setup" instructions for the JSP engine. 🔹<%@ page ... %>: Imports classes and sets page properties (like session="true"). 🔹<%@ include ... %>: Merges other files (Headers/Footers) during translation. 🔹<%@ taglib ... %>: Enables powerful tag libraries like JSTL. 📝 2. Scripting Elements (The Logic) This is where the magic happens. Many developers confuse these: 🔹Declarations <%! ... %>: Use this to define variables and methods. 🔹Scriptlets <% ... %>: The "Engine Room." Write your Java logic here (if-else, for-loops). 🔹Expressions <%= ... %>: Use this purely to display (print) data to the user. 🌐 3. The 4 Scopes (The Memory) 🔹Page: Lives only for the current page. 🔹Request: Lasts for one full request/response cycle. 🔹Session: Stays with the user while they browse. 🔹Application: Shared by every single user on the server. 💻 The "Ultimate Cheat Sheet" Code <%@ page language="java" contentType="text/html; charset=UTF-8" import="java.util.Date" %> <html> <body> <%! int hitCount = 0; %> <% hitCount++; // Incrementing our declared variable String timeOfDay = ""; int hour = new java.util.GregorianCalendar().get(java.util.Calendar.HOUR_OF_DAY) if(hour < 12) timeOfDay = "Morning"; else timeOfDay = "Evening"; request.setAttribute("greeting", "Good " + timeOfDay); %> <h1><%= request.getAttribute("greeting") %>, Developer!</h1> <p>This page has been viewed <b><%= hitCount %></b> times.</p> <hr> <p>Server Time: <%= new Date() %></p> </body> </html> 💡 Summary for your feed: 🔹Directives = Setup 🔹Declarations = Definition 🔹Scriptlets = Logic 🔹Expressions = Output 🔹Scopes = Lifetime ✔️Mastering these ensures your backend remains organized and your web pages stay fast. ❓Which of these four was the hardest for you to grasp when you started? Let's discuss! 👇 #Java #JSP #BackendDevelopment #Coding #SoftwareEngineering #WebApps #JavaDeveloper
To view or add a comment, sign in
-
-
Day 24 — #100DaysOfJava ☕ Today I learned **JSP** — JavaServer Pages. And this is where Java meets the browser. For 23 days I have been writing backend code — logic, databases, architecture. Today I saw how Java actually sends something to a user's screen. --- Q.What is JSP? JSP = HTML + Java code running on the server. You write HTML like normal. But inside that HTML, you can embed Java code using special tags. The server runs that Java, produces the output, and sends pure HTML back to the browser. The user never sees Java. They just see the result. --- How it actually works — the flow every developer should know: Step 1 — Browser sends a request to the server. Step 2 — Server takes your JSP file and converts it into a Servlet automatically. Step 3 — That Servlet compiles and runs. Step 4 — Output is plain HTML sent back to the browser. You write JSP. Java handles the rest. --- Three things you write inside JSP: Scriptlet — for writing Java logic. <% int sum = 10 + 20; %> Expression — for printing a value directly into the page. <%= sum %> Directive — for page-level settings like importing classes. <%@ page import="java.util.*" %> --- JSP also gives you built-in objects for free — no setup needed: request — get data the user sent response — send data back to the user session — remember the user across multiple pages out — write output to the page These are available in every JSP file automatically. That is one of the reasons JSP was so popular for building web apps quickly. --- JSP vs Servlet — the honest difference: Servlet is pure Java. You write Java code that generates HTML. Powerful but messy — imagine writing out.println for every single HTML tag. Hard to maintain. JSP is HTML first. Java is embedded inside. Much easier to design pages. Better separation between UI and logic. In modern Java development — neither JSP nor raw Servlet is used for production apps. Spring Boot with REST APIs and a frontend framework has replaced them. But understanding JSP and Servlets is what makes Spring MVC make complete sense. You cannot understand the solution without understanding the problem it solved. --- What clicked today — every web framework in Java is built on top of Servlets underneath. Spring MVC, Spring Boot — all of it. When a request comes in, a Servlet is handling it. JSP taught me that foundation. Day 1 ..... ....... Day 24 To any Java developer reading this — did you learn JSP and Servlets before Spring Boot? Do you think beginners should still learn them? Drop your opinion below. 👇 #Java #JSP #Servlets #JavaWebDevelopment #BackendDevelopment #100DaysOfJava #JavaDeveloper #LearningInPublic #100DaysOfCode #SpringBoot #WebDevelopment #OpenToWork #HiringJavaDeveloper
To view or add a comment, sign in
-
Day 28 — #100DaysOfJava ☕ Today a user typed something in a browser. My Java code received it, processed it, and sent a response back. That is client-server communication. And I built it from scratch. --- What I built today. A simple login form in HTML. User types username and password. Clicks submit. A Java Servlet receives that data on the server, reads it, and sends a response back to the browser. No framework. No Spring. No magic. Just raw Java talking directly to an HTTP request. --- How it actually works — and why every Spring Boot developer should understand this. The browser submits a form with method="post" to action="./firstServlet". The server sees that URL and maps it to my Servlet — because of this one annotation: @WebServlet("/firstServlet") That annotation replaced an entire XML configuration file. One line. Done. The Servlet extends HttpServlet and overrides two methods: doGet() — handles GET requests. When someone just visits the URL. doPost() — handles POST requests. When someone submits a form. Inside doPost(): String username = request.getParameter("username"); String password = request.getParameter("password"); PrintWriter writer = response.getWriter(); writer.print("Hello " + username); request.getParameter() reads the form field by its name attribute. PrintWriter writes the response back to the browser. That is the complete cycle. Request in. Process. Response out. --- What this taught me that no tutorial explains clearly. Every HTTP request has a method — GET or POST. GET is for fetching data. POST is for sending data. This is not just a Servlet concept. This is how the entire web works. Every form submission, every API call, every button click in a web app — underneath it is either a GET or a POST going to a server somewhere. Understanding this at the Servlet level means REST APIs, Spring Boot controllers, and API design all make immediate sense. @WebServlet maps a URL to a Java class. In Spring Boot, @RequestMapping and @GetMapping do the exact same thing — just with more features. Same concept. Different syntax. --- What Spring Boot does that raw Servlets do not. With raw Servlets — I write doGet() and doPost() manually. I configure the server. I handle everything. With Spring Boot — @RestController and @GetMapping handle all of this automatically. The Servlet container is embedded. Configuration is automatic. But here is the thing — Spring Boot is doing Servlet work underneath. It IS a Servlet application. Understanding the foundation means I will never be confused by what Spring Boot is doing for me. --- One thing I noticed in my own code today. I printed the password directly in the response: writer.print("I know your password " + password) Day 1 ... .......Day 28 To any developer reading this — what was the moment HTTP requests finally clicked for you? Drop it below. 👇 #Java #Servlets #HttpServlet #BackendDevelopment #WebDevelopment #100DaysOfJava #JavaDeveloper #LearningInPublic
To view or add a comment, sign in
-
📘 #Day116 of My Java Full Stack Journey Today I learned about Implicit Objects in JSP These objects help us handle requests, responses, sessions, and application data directly inside JSP pages. ✨ 𝐖𝐡𝐚𝐭 𝐚𝐫𝐞 𝐉𝐒𝐏 𝐈𝐦𝐩𝐥𝐢𝐜𝐢𝐭 𝐎𝐛𝐣𝐞𝐜𝐭𝐬? Implicit objects are automatically created by the JSP container and are available inside every JSP page. ➜ We don’t need to declare or initialize them manually. There are 9 implicit objects in JSP. 1️⃣ 𝒓𝒆𝒒𝒖𝒆𝒔𝒕: Represents the client request. ➜ Used to read data sent by the browser. 𝒎𝒆𝒕𝒉𝒐𝒅𝒔: ▪ getParameter() ▪ getAttribute() 2️⃣ 𝒓𝒆𝒔𝒑𝒐𝒏𝒔𝒆: Used to send response back to the browser. 𝒎𝒆𝒕𝒉𝒐𝒅𝒔: ▪ sendRedirect() ▪ setContentType() 3️⃣ 𝒐𝒖𝒕: Used to print output directly to the browser. 𝑬𝒙: <%= "Hello JSP" %> ➜ Internally uses: out.println() 4️⃣𝒔𝒆𝒔𝒔𝒊𝒐𝒏: Used to store user data across multiple requests. 𝑬𝒙: ▪ session.setAttribute() ▪ session.getAttribute() ➜ Commonly used for login sessions. 5️⃣ 𝒂𝒑𝒑𝒍𝒊𝒄𝒂𝒕𝒊𝒐𝒏: Represents the ServletContext object. ➜ Used to store data shared across the entire application. 𝑬𝒙: ▪ application.setAttribute() ▪ application.getAttribute() 6️⃣ 𝒄𝒐𝒏𝒇𝒊𝒈: Represents ServletConfig object. ➜ Used to get servlet configuration details. 𝑬𝒙: config.getInitParameter() 7️⃣ 𝒑𝒂𝒈𝒆𝑪𝒐𝒏𝒕𝒆𝒙𝒕: Provides access to all JSP scopes: ▪ page scope ▪ request scope ▪ session scope ▪ application scope ➜ Acts like a central access object in JSP. 8️⃣ 𝒑𝒂𝒈𝒆: Represents the current JSP page object. Similar to this keyword in Java. 9️⃣ 𝒆𝒙𝒄𝒆𝒑𝒕𝒊𝒐𝒏: Used only in error pages (when isErrorPage="true" is set in page directive). Helps handle exceptions in JSP. 𝑬𝒙: <%@ page isErrorPage="true" %> <%= exception.getMessage() %> ✨ 𝑾𝒉𝒚 𝑰𝒎𝒑𝒍𝒊𝒄𝒊𝒕 𝑶𝒃𝒋𝒆𝒄𝒕𝒔 𝒂𝒓𝒆 𝑼𝒔𝒆𝒇𝒖𝒍? ▪ No need to create objects manually ▪ Helps access request and response easily ▪ Supports session tracking ▪ Makes JSP coding faster and simpler Gurugubelli Vijaya Kumar | 10000 Coders #Java #JSP #ImplicitObjects #JavaWebDevelopment #FullStackJourney #BackendDevelopment
To view or add a comment, sign in
-
# Understanding Java Servlets: How Web Applications Work Internally 🚀 Recently, I started diving deeper into Java Servlets and explored how web applications actually work behind the scenes. ## What is a Servlet? A Servlet is a server-side Java component that follows the request-response model. When a client sends a request, the web container (such as Apache Tomcat) maps it to the appropriate servlet, processes it, and sends back a dynamic response. ## Servlet Lifecycle The lifecycle of a servlet is managed by the container: * init() → Invoked once to initialize resources * service() → Handles each incoming request * destroy() → Cleans up resources before the servlet is removed Internally, the service() method delegates requests to doGet(), doPost(), etc., depending on the HTTP method type. ## doGet() vs doPost() Understanding these methods helped me clearly differentiate how data flows: * doGet() * Data is appended to the URL * Can be cached * Used for retrieving data (idempotent operations) * doPost() * Data is sent in the request body * Not cached * Preferred for sensitive or state-changing operations ## Multithreading in Servlets One of the most interesting concepts is how servlets handle multiple users. A single servlet instance processes multiple requests concurrently using threads. This improves performance but also introduces challenges like race conditions when shared data is involved. Proper synchronization is required to maintain thread safety. ## Request and Response Objects Servlets use: * HttpServletRequest → to read client data * HttpServletResponse → to send response back These objects play a key role in handling communication between client and server. ## Key Takeaways Through this learning, I gained a clear understanding of: * How backend systems process requests * How multiple users are handled efficiently * The importance of HTTP methods and data handling ## What’s Next? I’m planning to integrate Servlets with JDBC and build a complete authentication system. --- This is part of my journey into backend development and system design.
To view or add a comment, sign in
-
Real world projects in production... At Architectural level - Java (Spring boot) 1) AOP implementation 2) Cache management 3) Interceptor 4) Global exception handling 5) Thread management 6) database integration 7) Microservices communication At Architectural level - Angular 1) Microfrontend communication. (using Module federation) 2) shared library to share components , directives between different microfrontends. 3) proxy file (CORS) to connect with backend (Java) 4) Generic components 5) cache management 6) Prevention from different attacks like... XSRF, XSS etc. At service level (Java): 1) Always use Composition over inheritance 2) Validations like @notnull, @notEmpty etc.. 3) use of var keyword 4) memeory leak prevention through weakHashMap 5) MVC: creating a controller , model, repository and service file. 6) use of virtual threads for multi-Threaded Environment. 7) Use of signals instead of traditional approach of for loop iterations. At Component Level (Angular) 1) creating directives and pipes. 2) use of scss for styling different components 3) use of structural directives @If, @for track: trackId 4) use of @defer for lazy loading of components 5) routing file for different routes let say /home, /dashboard, /user/:id etc... 6) standalone components 7) Use of Signals for forms and reactive programming 8) Interpolation 9) two way binding through ngModel Integration of frontend and backend and database is done with 1) At frontend (Angular) , field--> target: 'http://localhost:8080' in proxy.json file. (let's say your backend Java is running on localhost:8080) 2) At backend (Java) , application.properties file has i) base URL /api (org/system name), ii) server.port=8080 iii) database url: spring.datasource.url=jdbc:mysql://localhost:3306/your_db_name (let's say mySQL is running on localhost:3306.) Hope this helps! 😊 #architecture #angular #integration #realworldprojects #productionscale #java #springboot #javafullstack #springboot #mysql #latestfeatures
To view or add a comment, sign in
-
Wanted to share a few learnings from a recent backend upgrade we did. ⚙️ We moved one of our services to a newer Java, Spring, and Hibernate stack, and one thing became very clear: Big upgrades usually don’t fail at the compiler boundary. They fail at the assumption boundary. For us, the real work was not just the JDK upgrade. It was aligning everything around it: persistence mappings date/time behavior JSON serialization One of the earliest signals came from date/time handling. Before moving to java.time, we saw that some flows still using legacy java.sql.* types were not behaving correctly after the upgrade. In multiple cases, timestamp values were ending up in the database as 00:00:00.000 instead of carrying the expected time component. That created major issues across dev env because downstream flows were now reading and acting on incomplete or incorrect timestamps. That was the point where it became clear: this was not just a framework upgrade problem. It was a type-system and consistency problem. So we moved legacy JDBC-era date/time handling toward java.time, especially LocalDateTime. Java 21 does not suddenly reject java.sql.Date or java.sql.Timestamp, but modern frameworks definitely favor java.time. And with Hibernate 6.6.x, that path is much cleaner and more predictable. Why that mattered: older java.sql.* types were still “working” in parts of the system, but they became a poor fit across the full stack, especially once we looked at: ORM mappings Redis serialization integration flows consistency of behavior across layers The second issue was quieter, but just as important. 🧩 Once LocalDateTime entered one of our Redis-backed JSON flows, serialization started failing with: InvalidDefinitionException: Java 8 date/time type `java.time.LocalDateTime` not supported by default The root cause was a custom ObjectMapper. The fix: OBJECT_MAPPER.registerModule(new JavaTimeModule()); OBJECT_MAPPER.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); Why this mattered: JavaTimeModule teaches Jackson how to handle java.time types disabling WRITE_DATES_AS_TIMESTAMPS makes unannotated date/time fields serialize as readable strings by default instead of timestamp/array-style output In short: the upgrade exposed hidden consistency gaps. The API layer may be fine, but caches, async flows, and internal serializers can still be operating under very different assumptions. A few takeaways from this upgrade 👇 JDK upgrades are often the easy part date/time migration deserves first-class attention Hibernate 6.6.x is far happier when your model uses java.time custom ObjectMappers are hidden compatibility surfaces consistency across DB, API, cache, and integrations matters more than “it compiles” #Java21 #SpringBoot #Hibernate #BackendEngineering #SoftwareArchitecture #TechLearning
To view or add a comment, sign in
-
📘 #Day115 of My Java Full Stack Journey Today I started learning JSP (JavaServer Pages), which is used to create dynamic web pages in Java web applications. ✨ 𝐖𝐡𝐚𝐭 𝐢𝐬 𝐉𝐒𝐏? JSP (JavaServer Pages) is a server-side technology used to create dynamic web content. ➜ It allows us to write HTML along with Java code inside a single file. ➜ JSP runs inside a Servlet container like Apache Tomcat. ➜ Before sending the response to the browser, JSP is automatically converted into a Servlet by the server. ✨ 𝐖𝐡𝐲 𝐉𝐒𝐏 𝐢𝐬 𝐍𝐞𝐞𝐝𝐞𝐝? While working with Servlets, generating HTML using Java code becomes difficult to manage. JSP solves this problem by separating presentation logic from business logic. JSP helps to: ➜ Write HTML easily ➜ Reduce Java code inside Servlets ➜ Improve readability of web pages ➜ Support faster development of UI ✨ 𝐉𝐒𝐏 𝐯𝐬 𝐒𝐞𝐫𝐯𝐥𝐞𝐭 𝑺𝒆𝒓𝒗𝒍𝒆𝒕: ▪ Used mainly for processing logic ▪ Writing HTML inside Java code is difficult 𝑱𝑺𝑷: ▪ Used mainly for designing UI pages ▪ Allows writing Java inside HTML easily ▪ Internally converted into Servlet ➜ So JSP is mainly used for the presentation layer, while Servlets handle processing logic. ✨ 𝐉𝐒𝐏 𝐄𝐥𝐞𝐦𝐞𝐧𝐭𝐬 JSP provides special elements to write Java code inside HTML. 1️⃣ Scriptlet: Scriptlet is used to write Java code inside JSP. 𝑬𝒙: <% out.println("Hello JSP"); %> 2️⃣ Expression: Expression is used to print output directly to the browser. 𝑬𝒙: <%= "Welcome to JSP" %> 3️⃣ Directive: Directive is used to provide instructions to the JSP container. 𝑬𝒙: <%@ page language="java" contentType="text/html" %> ✨ 𝐇𝐨𝐰 𝐉𝐒𝐏 𝐖𝐨𝐫𝐤𝐬? Browser → Request → JSP → Converted into Servlet → Response → Browser 📌 𝐊𝐞𝐲 𝐋𝐞𝐚𝐫𝐧𝐢𝐧𝐠𝐬 ▪ JSP is used to create dynamic web pages ▪ JSP runs inside Servlet container (Tomcat) ▪ JSP is internally converted into Servlet ▪ Scriptlet is used to write Java code ▪ Expression prints output directly to browser ▪ Directive provides instructions to JSP container Gurugubelli Vijaya Kumar | 10000 Coders #Java #JSP #JavaServerPages #JavaWebDevelopment #FullStackJourney #BackendDevelopment
To view or add a comment, sign in
-
-
#Day81 🚀 || AI Powered Java Full Stack Course 💻 Advanced Java | 🌐 Introduction to JSP, Scripting Elements & Scopes with Frontlines EduTech (FLM) Hello connections 👋😊 As part of my AI Powered Java Full Stack Course, today’s session introduced Java Server Pages (JSP) — a powerful server-side technology used to build dynamic and interactive web applications 💡🚀 Today marks 📅 Day 81 of my learning journey, where I explored how JSP simplifies web development by seamlessly combining HTML and Java code in a single file 🌐 🔹 🌐 Introduction to JSP JSP (Java Server Pages) enables developers to create dynamic web pages by embedding Java code directly into HTML 🧩 ✨ Key points: • Java code is executed on the server side • The processed result is sent to the browser as HTML • Helps in building dynamic and user-interactive applications 🔹 🎯 Purpose of JSP ✨ • Generates dynamic content efficiently • Simplifies UI development compared to Servlets • Reduces boilerplate code by integrating Java with HTML 🔹 🛠️ Creating a JSP File ✨ Steps: • Navigate to the webapp directory • Create a file with .jsp extension (e.g., index.jsp) 👉 Acts as the entry point for rendering web pages 🔹 🧩 JSP Scripting Elements JSP provides special elements to embed Java code within HTML 🔗 ✨ Types of scripting elements: • Scriptlet Tag → <% Java code %> 👉 Used for implementing business logic (loops, conditions) • Expression Tag → <%= expression %> 👉 Outputs data directly to the browser • Declaration Tag → <%! declaration %> 👉 Used to declare variables and methods at class level 🔹 🔄 JSP Scopes Scopes are used to store and share data across different components of a web application 📊 ✨ Types of scopes: • Request Scope 📥 👉 Stores data for a single request-response cycle 👉 Commonly used between Servlet and JSP (forwarding) • Session Scope 🔐 👉 Stores data across multiple requests for a single user session 👉 Data persists until session expires or browser is closed • Application Scope 🌍 👉 Stores data shared across the entire application 👉 Accessible by all users and components 🔹 ⚠️ Important Note ✨ • getAttribute() returns data as Object type • Requires typecasting while retrieving values 💡 Today’s Takeaway: JSP simplifies the development of dynamic web pages by bridging the gap between frontend (HTML) and backend (Java). Understanding scripting elements and scopes is crucial for managing data flow effectively in real-world web applications 💯🚀 🙏 Special thanks to Krishna Mantravadi, Upendra Gulipilli, and my trainer Fayaz S for their continuous guidance 💡 #Java #JSP #AdvancedJava #WebDevelopment #Servlets #JavaFullStack #BackendDevelopment #LearningJourney #AIPoweredJavaFullStack #FrontlinesEdutech #FLM 🚀
To view or add a comment, sign in
-
-
🎯 Interviewer: What happens when you call a REST API in Spring Boot? 🤔 When a REST API is called in Spring Boot, the request goes through multiple layers before returning a response. Let me walk you through it step by step: 🟢 1. HTTP Request Arrives -> Client sends a request (GET/POST/PUT/DELETE) -> It hits the server (e.g., localhost:8080) -> Embedded Tomcat receives the request -> A thread is picked from the thread pool (default ~200 threads) 🟡 2. Servlet Filter Chain (Pre-processing) Before reaching Spring, request passes through filters: -> Security Filter → Authentication & Authorization -> CORS Filter → Validates origin -> Logging Filter → Logs request details -> Custom Filters → Any custom logic 👉 If any filter rejects → request ends here 🔵 3. DispatcherServlet (Front Controller) -> Central component of Spring MVC -> Receives request after filters -> Uses HandlerMapping to find the correct controller method (@GetMapping, @PostMapping, etc.) 🟠 4. HandlerInterceptor (PreHandle) -> Runs before controller method: -> Rate limiting -> Authentication checks (if custom) -> Logging/validation 👉 Can block request before controller 🟣 5. Argument Resolution ( Important ) -> Spring prepares method parameters automatically: @RequestParam → Query params @PathVariable → URL values @RequestBody → JSON → Java Object @RequestHeader → Headers 👉 Done using HandlerMethodArgumentResolver 🟢 6. Controller Execution (@RestController) -> Your controller method executes Calls: ->Service Layer (business logic) ->Repository Layer (DB operations) 👉 Returns: ->Object (POJO) ->ResponseEntity ->DTO 🟡 7. Response Conversion -> Spring uses HttpMessageConverters -> Converts Java object → JSON/XML 🔵 8. HandlerInterceptor (PostHandle & AfterCompletion) => After controller execution: ->Modify response (PostHandle) ->Logging/cleanup (AfterCompletion) 🟠 9. Servlet Filter Chain (Reverse Order) -> Response passes again through filters -> Executed in reverse order 🟣 10. HTTP Response Sent -> Final response returned to client -> Thread is released back to the pool 🎯 Key Takeaways Filters → Before Spring DispatcherServlet → Brain of Spring MVC Interceptors → preHandle() → BEFORE Controller, postHandle() -> After Controller, Before Response, afterCompletion() → AFTER Everything Argument Resolver → Converts request → Java Message Converter → Converts Java → Response #SpringBoot #Java #BackendDevelopment #RestAPI #SpringFramework #Microservices #SystemDesign #SoftwareEngineering #WebDevelopment #InterviewPreparation #CodingInterview #LearnInPublic #Programming #Developers #Tech #DevCommunity
To view or add a comment, sign in
-
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development