Servlet welcome-file-list

welcome-file-list: The welcome-file-list attribute of the web.xml file is used to define the list of welcome files. Sample code of welcome-file-list attribute in web.xml: <web-app> //other attributes <welcome-file-list> <welcome-file>home.html</welcome-file> <welcome-file>welcome.html</welcome-file> </welcome-file-list> //other attributes </web-app>   How it works: The first web server looks for the welcome-file-list if it exists then it looks for the file … Read more

Java HttpServlet Class

HttpServlet class: HttpServlet class extends the GenericServlet. It is protocol-dependent. public abstract class HttpServlet extends GenericServlet HttpServlet class is in javax.servlet.http package (javax.servlet.http.HttpServlet). Methods of HttpServlet class: 1. service(ServletRequest req,ServletResponse res): Dispatches the requests to the protected service method. It converts the request and response object into HTTP type before dispatching the request. Syntax: public void service(ServletRequest req, ServletResponse res) … Read more

GenericServlet class in java

GenericServlet class: GenericServlet class implements the Servlet and ServletConfig interfaces. GenericServlet is protocol-independent. It not provides the implementation of service method. public abstract class GenericServlet implements Servlet, ServletConfig GenericServlet class is in javax.servlet package (javax.servlet.GenericServlet). Methods of GenericServlet class: 1. init(ServletConfig config): It is used to initialize the servlet. This method is called only once by the web container when it loads the servlet. Syntax: public void … Read more

Servlet interface in java

Servlet interface: The Servlet interface contains the common methods for all servlets i.e. provides the common behavior for all servlets. public interface Servlet Servlet interface is in javax.servlet package (javax.servlet.Servlet). Methods of servlet interface: 1. init(ServletConfig config): It is used to initialize the servlet. This method is called only once by the web container when it … Read more

JavaMail API sending email

As we discussed in earlier tutorials that SMTP server is responsible for sending emails so we need SMTP server to send email from our java application. We can get the SMTP server by using any one of the following techniques: Install and use any SMTP server such as Postfix server, Apache James server etc. Use … Read more

JavaMail API core classes

The javax.mail and javax.mail.internet package consist the commonly used core classes for JavaMail API. Commonly used core classes of JavaMail API: javax.mail.Session javax.mail.Message javax.mail.internet.MimeMessage javax.mail.Address javax.mail.internet.InternetAddress javax.mail.Authenticator javax.mail.Transport javax.mail.Store javax.mail.Folder   1. javax.mail.Session: The Session class is the primary class for JavaMail API. The Session object is used to handle configuration setting and authentication and … Read more

Log4j multiple appenders

Let us discuss the use of multiple appenders with the help of below example. In this example we are using two appenders CA(Console Appender) and FA(File Appender) with different configurations. Example: Log4jTest.java import org.apache.log4j.Logger;   /** * This class is used to show the use of * multiple appenders with the log4j.properties file. * @author … Read more

Log4j file appender

Let us discuss the use of file appenders with the help of below example. Example: Log4jTest.java import org.apache.log4j.Logger;   /** * This class is used to show the use of * file appender with the log4j.properties file. * @author w3schools */ public class Log4jTest { //Get the Logger object. private static Logger log = Logger.getLogger(Log4jTest.class); … Read more