import java.io.IOException; import javax.servlet.ServletException; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; import javax.servlet.ServletConfig; import javax.servlet.annotation.WebServlet; @WebServlet("/lifecycle") public class LifecycleServlet implements javax.servlet.Servlet { public void init(ServletConfig config) throws ServletException { System.out.println("Servlet Initialized"); } public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException { System.out.println("Servlet is servicing the request"); } public void destroy() { System.out.println("Servlet Destroyed"); } public ServletConfig getServletConfig() { return null; } public String getServletInfo() { return null; } } web.xml <web-app xmlns="http://java.sun.com/xml/ns/javaee" version="3.0"> <servlet> <servlet-name>LifecycleServlet</servlet-name> <servlet-class>LifecycleServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>LifecycleServlet</servlet-name> <url-pattern>/lifecycle</url-pattern> </servlet-mapping> </web-app>
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter