Category Archives: Без рубрики

Java.Servlet.How can you implement servlet startup at the same time as the application startup?

If you want your servlet to initialize immediately when the web application starts (instead of waiting for the first request), the solution is simple and powerful: ✅ Use load-on-startup in web.xml This tells the servlet container to load and initialize … Continue reading →

Posted in Без рубрики | Comments Off on Java.Servlet.How can you implement servlet startup at the same time as the application startup?

Java.Servlets.When should you use servlet filters and when listeners?

Servlet Filters and Servlet Listeners are both powerful tools — but they serve very different purposes. Let’s break it down: 🧭 TL;DR: When to Use What Feature Use Filters When… Use Listeners When… 🔁 Request/Response You want to modify or … Continue reading →

Posted in Без рубрики | Comments Off on Java.Servlets.When should you use servlet filters and when listeners?

Java.Servlets.Listeners

🎯 Why Use Listeners? They let you hook into the lifecycle of: The ServletContext (entire app) HttpSession (per user) ServletRequest (per request) You use them to: Initialize or clean up resources (e.g. DB pools) Log application or session events Track … Continue reading →

Posted in Без рубрики | Comments Off on Java.Servlets.Listeners

Java.Servlet.What do you know about servlet filters?

Servlet filters are like middleware in Java web applications — they allow you to intercept and modify requests and responses before they reach a servlet or after the servlet processes them. 🧰 What Is a Servlet Filter? A filter is … Continue reading →

Posted in Без рубрики | Comments Off on Java.Servlet.What do you know about servlet filters?

Java.Servlet.What are the most common tasks performed in a servlet container?

The servlet container (like Tomcat, Jetty, or Undertow) does a lot of behind-the-scenes heavy lifting so your servlet code can focus just on business logic. Let’s look at the most common and critical tasks a servlet container performs: ⚙️ Most … Continue reading →

Posted in Без рубрики | Comments Off on Java.Servlet.What are the most common tasks performed in a servlet container?

Java.Servlet.Why is it necessary to override only the init() method without arguments?

🧠 There Are Two init() Methods in Servlets: 📌 So… why is it usually enough (and preferred) to override only the no-arg init()? Here’s the Explanation: 1. Servlet API Design Handles ServletConfig for You If your servlet extends HttpServlet, then … Continue reading →

Posted in Без рубрики | Comments Off on Java.Servlet.Why is it necessary to override only the init() method without arguments?

Java.Servlet.Does it make sense to define a constructor for a servlet? What is the best way to initialize data?

Technically, yes, you can define a constructor in a servlet, but… ⚠️ You Should Avoid Putting Initialization Logic in It. Here’s why: 🚫 Why Not Use Constructor for Initialization? Servlet container controls instantiation — not you. ServletConfig and ServletContext are … Continue reading →

Posted in Без рубрики | Comments Off on Java.Servlet.Does it make sense to define a constructor for a servlet? What is the best way to initialize data?

Java.Servlet.When is it necessary to override the service() method?

In most servlet-based applications, you don’t need to override the service() method — you override doGet(), doPost(), etc. But there are specific situations where overriding service() makes sense. 🧠 First, What Does service() Do? The service() method is part of … Continue reading →

Posted in Без рубрики | Comments Off on Java.Servlet.When is it necessary to override the service() method?

Java.Servlets.What steps should be taken when creating servlets?

🛠️ Steps to Create a Servlet (Classic web.xml Approach) ✅ 1. Create a Java Class That Extends HttpServlet ✅ 2. Compile the Servlet Make sure to include the servlet API jar in your classpath: ✅ 3. Create a Deployment Structure … Continue reading →

Posted in Без рубрики | Comments Off on Java.Servlets.What steps should be taken when creating servlets?

Java.Servlets.What is deployment descriptor ?

📄 What is it exactly? ➤ File Name: ➤ It’s read by the servlet container (like Tomcat) when deploying your app. 🧠 What It Does: Maps URLs to servlets Declares filters, listeners Configures session settings Sets up security (authentication, roles) … Continue reading →

Posted in Без рубрики | Comments Off on Java.Servlets.What is deployment descriptor ?