SERVLET / CATATAN</>↗Servlet25 Apr 2025
In Jakarta EE (formerly Java EE), you can use listeners like ServletContextListener to manage the lifecycle of a web application’s ServletContext. It provides hooks to execute logic during the initialization and destruction stages of the application. This can be useful for resource initialization, cleanup, or logging purposes. Here’s how you can use ServletContextListener: 1. Implementing […]
SERVLET / CATATAN</>↗Servlet25 Apr 2025
Handling exceptions and errors in Jakarta Servlets involves several approaches, ranging from defining error-handling configurations in the deployment descriptor (web.xml) to using annotations and specific coding practices. Below are the typical ways to handle errors and exceptions in Jakarta Servlets: 1. Using web.xml for Declarative Exception Handling In the web.xml file, you can define error […]
JSCH / CATATAN</>↗JSch24 Apr 2025
To list the contents of a directory on a remote server using JSch (a Java library for SSH), you need to establish an SSH connection and use the SFTP protocol to query the directory. Here’s how you can do it programmatically: Steps to List Directory Contents: Establish a session: Connect to the remote server with […]
SERVLET / CATATAN</>↗Servlet24 Apr 2025
Using AsyncContext in servlets allows you to perform asynchronous request processing. This can improve scalability in situations where a request might involve long-running operations, such as external API calls or database queries, by freeing up server threads while those tasks are performed. Here’s how you can use AsyncContext for asynchronous processing in a servlet: 1. […]
SERVLET / CATATAN</>↗Servlet24 Apr 2025
In Java servlets, you can use the ServletContext.log() method to log messages, exceptions, or context-specific information. The ServletContext object is available in your servlet and allows you to log messages to the server’s log file. Here are the common ways you can log using ServletContext.log(): 1. Logging a simple message: You can log plain text […]
JSCH / CATATAN</>↗JSch24 Apr 2025
To authenticate using a username and password with the JSch library (used for SSH connections in Java), you can follow these steps: Add JSch Dependency Make sure your project includes the JSch library. You can add it using Maven or Gradle if you’re using a build system. For Maven: <dependency> <groupId>com.jcraft</groupId> <artifactId>jsch</artifactId> <version>0.1.55</version> </dependency> For […]