JSCH / NOTES</>↗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 / NOTES</>↗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 / NOTES</>↗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 / NOTES</>↗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 […]
SERVLET / NOTES</>↗Servlet23 Apr 2025
Securing servlets with declarative security in the web.xml deployment descriptor is an essential practice in Java web applications. It allows you to define security constraints without writing specific code, instead leveraging the standard configuration mechanism in web.xml. Here’s how you can do it step-by-step: 1. Define a Security Constraint The <security-constraint> element is used to […]
SERVLET / NOTES</>↗Servlet23 Apr 2025
In Jakarta Servlet 6.0+, file uploads can be handled efficiently using the native APIs provided by the servlet specifications. Here’s a step-by-step guide: 1. Enable Multipart Config for the Servlet To handle file uploads, the servlet must be annotated with @MultipartConfig, which enables support for handling multipart/form-data requests. You can configure parameters such as maximum […]