SERVLET / CATATAN</>↗Servlet20 Apr 2025
You can initialize servlet parameters in a Java Servlet by using the ServletConfig object. The ServletConfig object contains initialization parameters and configuration data for a specific servlet. These parameters are specified in the web application’s deployment descriptor (web.xml file). Here’s a step-by-step guide to using ServletConfig for initializing servlet parameters: 1. Define Initialization Parameters in […]
SERVLET / CATATAN</>↗Servlet20 Apr 2025
Creating a servlet filter using the Filter interface and FilterChain is straightforward in Jakarta EE (or Java EE). A filter is used to perform filtering tasks like logging, authentication, authorization, etc., on requests or responses. Here’s how you can create a servlet filter step by step: Steps to Create a Servlet Filter Implement the Filter […]
SERVLET / CATATAN</>↗Servlet19 Apr 2025
In Jakarta EE, you can define servlets using annotations instead of the traditional web.xml deployment descriptor. The most common annotation used for this purpose is @WebServlet. Here’s an overview of how to use annotations to define servlets: 1. Basic Syntax of the @WebServlet Annotation The @WebServlet annotation is used to declare a servlet and map […]
SERVLET / CATATAN</>↗Servlet19 Apr 2025
In a Jakarta EE (formerly Java EE) application, you can configure servlets in the web.xml deployment descriptor. The web.xml file is located in the WEB-INF directory of your project. Here’s how you can configure a servlet in web.xml step-by-step: 1. Declare the Servlet You define the servlet by giving it a name and specifying its […]
SERVLET / CATATAN</>↗Servlet18 Apr 2025
Handling cookies in the Jakarta Servlet API is simple and straightforward. Cookies are small bits of data sent from a server to a client and then sent back by the client in subsequent requests to the server. Below is how you can handle cookies using Jakarta Servlet API: 1. Creating and Adding a Cookie To […]
SERVLET / CATATAN</>↗Servlet18 Apr 2025
To set response headers using HttpServletResponse in a Java web application (e.g., within a servlet), you can use the setHeader or addHeader methods provided by the HttpServletResponse class. Here’s an overview of both methods and how to use them: Methods for Setting Headers setHeader(String name, String value) This method sets a response header with a […]