SERVLET / CATATAN</>↗Servlet17 Apr 2025
To include the content of one servlet or JSP into another, you can use the functionality provided by the RequestDispatcher interface in Jakarta Servlet (previously Javax Servlet). The two primary methods for including content are: Using RequestDispatcher.include(): This method includes the response of another servlet or JSP within the response of the current servlet or […]
SERVLET / CATATAN</>↗Servlet17 Apr 2025
In Java, the RequestDispatcher is used to forward a client’s request to another resource, such as a servlet, JSP, or HTML file. This is common when you want to break down the processing of a request into multiple components. Syntax to Use RequestDispatcher The RequestDispatcher interface provides two main methods to forward or include content: […]
HTTPCLIENT / CATATAN</>↗HttpClient16 Apr 2025
To set a timeout on HTTP requests in Java 11, you can use the HttpClient provided by the java.net.http module. The HttpClient API allows you to configure timeouts for requests in a convenient and standardized way. Here’s how you can do it: Set a Connection Timeout: This controls the timeout when establishing a connection to […]
HTTPCLIENT / CATATAN</>↗HttpClient16 Apr 2025
In Java 11, the java.net.http package introduced the new HttpClient API, which simplifies working with HTTP requests and responses. To set custom headers for an HttpRequest, you can use the headers method or the setHeader method while building your request using the HttpRequest.Builder. Here’s a step-by-step guide for setting custom headers: Example Code package org.kodejava.net.http; […]
HTTPCLIENT / CATATAN</>↗HttpClient15 Apr 2025
Handling HTTP response status codes with Java 11’s HttpClient API involves making a request, receiving a response, and then checking the status code returned in the response. Here’s how you can do this: Steps to Handle HTTP Response Status Codes Create the HttpClient: Build an instance of HttpClient. Build the Request: Define the HTTP request […]
CONCURRENCY / CATATAN</>↗Concurrency15 Apr 2025
In Java, the Callable interface and Future interface are used in conjunction to run tasks asynchronously in a separate thread and fetch the result of the computation once it is complete. This is particularly useful when you need the task to return a result or throw a checked exception. Here’s a step-by-step guide to how […]