SlideShare a Scribd company logo
This App contains the codes in two phases
1. LifeCycleTest Codes
2. web.xml codes
note: form a web module and deploy these codes there and
enjoy.
Servlet Life-Cycle Test-App codes
package com.nt;
importjava.io.IOException;
importjava.io.PrintWriter;
importjava.util.Date;
importjavax.servlet.ServletConfig;
importjavax.servlet.ServletException;
importjavax.servlet.ServletRequest;
importjavax.servlet.ServletResponse;
importjavax.servlet.annotation.WebServlet;
importjavax.servlet.http.HttpServlet;
/**
* ServletimplementationclassLCTestSrv
*/
@WebServlet("/LCTestSrv")
publicclassLCTestSrvextendsHttpServlet{
private staticfinal longserialVersionUID=1L;
static{
System.out.println("ServletClassloading:staticblock");
}
publicLCTestSrv() {
System.out.println("ServletClassobjectcreation:0-paramconstructor");
}
publicvoidinit(ServletConfigcfg){
System.out.println("ServletClassobjectinitialization:init(-) execution");
}
publicvoidservice(ServletRequestreq,ServletResponseres) throwsServletException,IOException{
System.out.println("RequestProcessingevent:service(-,-)execution");
//general settings
PrintWriterpw=res.getWriter();
res.setContentType("text/html");
//requestProcessinglogic
pw.println(newDate()+"<br/><br/>");
//logicforobjectshashcode generation
pw.println("<br><spanstyle=color:red>CurrentRequestHashcode:</span>
"+req.hashCode());
pw.println("<br><spanstyle=color:red>CurrentResponse Hashcode:</span>
"+req.hashCode());
pw.println("<br><spanstyle=color:red>CurrentThreadHashcode:</span>
"+Thread.currentThread().hashCode());
pw.println("<br><spanstyle=color:red>ServletobjectHashcode:</span>
"+this.hashCode());
try{Thread.sleep(5000);}
catch(Exceptione){e.printStackTrace();}
//close stream
pw.close();
}
publicvoiddestroy(){System.out.println("ServletContainorcalleddestroymethodjustbefore
destroyingServletObject..");}
}
web.xml codes
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-
instance" xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<display-name>ServletLifeCycleDemoApp</display-name>
<servlet>
<servlet-name>lc</servlet-name>
<servlet-class>com.nt.LCTestSrv</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>lc</servlet-name>
<url-pattern>/lcurl</url-pattern>
</servlet-mapping>
</web-app>

More Related Content

DOCX
Multiple Submit Button Test App
PPTX
Replicating production on your laptop using the magic of containers v2
PPTX
Replicating production on your laptop using the magic of containers
PPTX
SAST_QSDL
PDF
Identifing Listeners and Filters
PDF
Selenium XPath Performance Problems in IE
PDF
Jenkins – przyjaciel każdego testera.
PDF
Advanced Selenium Workshop
Multiple Submit Button Test App
Replicating production on your laptop using the magic of containers v2
Replicating production on your laptop using the magic of containers
SAST_QSDL
Identifing Listeners and Filters
Selenium XPath Performance Problems in IE
Jenkins – przyjaciel każdego testera.
Advanced Selenium Workshop

What's hot (19)

PDF
Install spark on_windows10
PPTX
Christophe Spring Actionscript Flex Java Exchange
PPTX
Springboot2 postgresql-jpa-hibernate-crud-example with test
PDF
Selenium RC - Web Application Testing Tool
PPTX
Spring Testing, Fight for the Context
PDF
Testing Web Apps with Spring Framework
PDF
San Jose Selenium Meet-up PushToTest TestMaker Presentation
PDF
Testing Spring Boot Applications
DOCX
Photo Insert and Retrieve App
PDF
Eclipse and Java 8 - Melbourne Java Meet Up
PPTX
Hybrid automation framework
PDF
API Testing following the Test Pyramid
DOCX
To study pcms pegasus erp cargo management system-release-7 from architectu...
PPTX
Maven TestNg frame work (1) (1)
PDF
Tizen Web Application Checker
PPTX
Springboot2 postgresql-jpa-hibernate-crud-example
PDF
Open Source Software Testing Tools
PDF
What’s new in Laravel 7.8?
PDF
Continuous Integration with TestMaker, Hudson, Jenkins, Bamboo
Install spark on_windows10
Christophe Spring Actionscript Flex Java Exchange
Springboot2 postgresql-jpa-hibernate-crud-example with test
Selenium RC - Web Application Testing Tool
Spring Testing, Fight for the Context
Testing Web Apps with Spring Framework
San Jose Selenium Meet-up PushToTest TestMaker Presentation
Testing Spring Boot Applications
Photo Insert and Retrieve App
Eclipse and Java 8 - Melbourne Java Meet Up
Hybrid automation framework
API Testing following the Test Pyramid
To study pcms pegasus erp cargo management system-release-7 from architectu...
Maven TestNg frame work (1) (1)
Tizen Web Application Checker
Springboot2 postgresql-jpa-hibernate-crud-example
Open Source Software Testing Tools
What’s new in Laravel 7.8?
Continuous Integration with TestMaker, Hudson, Jenkins, Bamboo
Ad

Similar to Servlet LifeCycle Demo App (20)

DOCX
Online Form Submission App
DOC
Java Servlets & JSP
PPTX
C#on linux
PPTX
Spring REST Request Validation
PDF
PDF
PPTX
Top 10 Mistakes AngularJS Developers Make
PPTX
Developing ASP.NET Applications Using the Model View Controller Pattern
PPTX
Struts Interceptors
PDF
Haj 4328-java ee 7 overview
PDF
Spring Performance Gains
PPTX
Chapter 3 servlet & jsp
PPTX
SERVLETS (2).pptxintroduction to servlet with all servlets
PPT
ASP.NET AJAX Basics
PPT
Module 5.ppt.............................
PPTX
AJppt.pptx
ODP
Wicket And Swing From One Codebase
PPTX
Vue js and Dyploma
PPTX
Станислав Сидоренко «DeviceHive Java Server – миграция на Spring Boot»
PPTX
Testing Microservices
Online Form Submission App
Java Servlets & JSP
C#on linux
Spring REST Request Validation
Top 10 Mistakes AngularJS Developers Make
Developing ASP.NET Applications Using the Model View Controller Pattern
Struts Interceptors
Haj 4328-java ee 7 overview
Spring Performance Gains
Chapter 3 servlet & jsp
SERVLETS (2).pptxintroduction to servlet with all servlets
ASP.NET AJAX Basics
Module 5.ppt.............................
AJppt.pptx
Wicket And Swing From One Codebase
Vue js and Dyploma
Станислав Сидоренко «DeviceHive Java Server – миграция на Spring Boot»
Testing Microservices
Ad

More from Peeyush Ranjan (9)

DOCX
Multiple Hyperlinks App
DOCX
Scrollable Test App
DOCX
Scrollable Demo App
DOCX
Cursor Demo App
DOCX
Batch processing Demo
DOCX
Transaction Management Tool
DOCX
Net Beans Codes for Student Portal
DOCX
TextSearch
DOCX
Multiple Hyperlinks App
Scrollable Test App
Scrollable Demo App
Cursor Demo App
Batch processing Demo
Transaction Management Tool
Net Beans Codes for Student Portal
TextSearch

Servlet LifeCycle Demo App

  • 1. This App contains the codes in two phases 1. LifeCycleTest Codes 2. web.xml codes note: form a web module and deploy these codes there and enjoy. Servlet Life-Cycle Test-App codes package com.nt; importjava.io.IOException; importjava.io.PrintWriter; importjava.util.Date; importjavax.servlet.ServletConfig; importjavax.servlet.ServletException; importjavax.servlet.ServletRequest; importjavax.servlet.ServletResponse; importjavax.servlet.annotation.WebServlet; importjavax.servlet.http.HttpServlet; /** * ServletimplementationclassLCTestSrv */ @WebServlet("/LCTestSrv") publicclassLCTestSrvextendsHttpServlet{ private staticfinal longserialVersionUID=1L; static{
  • 2. System.out.println("ServletClassloading:staticblock"); } publicLCTestSrv() { System.out.println("ServletClassobjectcreation:0-paramconstructor"); } publicvoidinit(ServletConfigcfg){ System.out.println("ServletClassobjectinitialization:init(-) execution"); } publicvoidservice(ServletRequestreq,ServletResponseres) throwsServletException,IOException{ System.out.println("RequestProcessingevent:service(-,-)execution"); //general settings PrintWriterpw=res.getWriter(); res.setContentType("text/html"); //requestProcessinglogic pw.println(newDate()+"<br/><br/>"); //logicforobjectshashcode generation pw.println("<br><spanstyle=color:red>CurrentRequestHashcode:</span> "+req.hashCode()); pw.println("<br><spanstyle=color:red>CurrentResponse Hashcode:</span> "+req.hashCode()); pw.println("<br><spanstyle=color:red>CurrentThreadHashcode:</span> "+Thread.currentThread().hashCode()); pw.println("<br><spanstyle=color:red>ServletobjectHashcode:</span> "+this.hashCode()); try{Thread.sleep(5000);} catch(Exceptione){e.printStackTrace();} //close stream pw.close(); } publicvoiddestroy(){System.out.println("ServletContainorcalleddestroymethodjustbefore destroyingServletObject..");}
  • 3. } web.xml codes <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema- instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"> <display-name>ServletLifeCycleDemoApp</display-name> <servlet> <servlet-name>lc</servlet-name> <servlet-class>com.nt.LCTestSrv</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>lc</servlet-name> <url-pattern>/lcurl</url-pattern> </servlet-mapping> </web-app>