SlideShare a Scribd company logo
1 of 3
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

What's hot

Install spark on_windows10
Install spark on_windows10Install spark on_windows10
Install spark on_windows10Ajay Ohri
 
Christophe Spring Actionscript Flex Java Exchange
Christophe Spring Actionscript Flex Java ExchangeChristophe Spring Actionscript Flex Java Exchange
Christophe Spring Actionscript Flex Java ExchangeSkills Matter
 
Springboot2 postgresql-jpa-hibernate-crud-example with test
Springboot2 postgresql-jpa-hibernate-crud-example with testSpringboot2 postgresql-jpa-hibernate-crud-example with test
Springboot2 postgresql-jpa-hibernate-crud-example with testHyukSun Kwon
 
Selenium RC - Web Application Testing Tool
Selenium RC - Web Application Testing ToolSelenium RC - Web Application Testing Tool
Selenium RC - Web Application Testing ToolAtsushi Sano
 
Spring Testing, Fight for the Context
Spring Testing, Fight for the ContextSpring Testing, Fight for the Context
Spring Testing, Fight for the ContextGlobalLogic Ukraine
 
Testing Web Apps with Spring Framework
Testing Web Apps with Spring FrameworkTesting Web Apps with Spring Framework
Testing Web Apps with Spring FrameworkDmytro Chyzhykov
 
San Jose Selenium Meet-up PushToTest TestMaker Presentation
San Jose Selenium Meet-up PushToTest TestMaker PresentationSan Jose Selenium Meet-up PushToTest TestMaker Presentation
San Jose Selenium Meet-up PushToTest TestMaker PresentationClever Moe
 
Testing Spring Boot Applications
Testing Spring Boot ApplicationsTesting Spring Boot Applications
Testing Spring Boot ApplicationsVMware Tanzu
 
Photo Insert and Retrieve App
Photo Insert and Retrieve AppPhoto Insert and Retrieve App
Photo Insert and Retrieve AppPeeyush Ranjan
 
Eclipse and Java 8 - Melbourne Java Meet Up
Eclipse and Java 8 - Melbourne Java Meet UpEclipse and Java 8 - Melbourne Java Meet Up
Eclipse and Java 8 - Melbourne Java Meet UpManju Mathew
 
Hybrid automation framework
Hybrid automation frameworkHybrid automation framework
Hybrid automation frameworkdoai tran
 
API Testing following the Test Pyramid
API Testing following the Test PyramidAPI Testing following the Test Pyramid
API Testing following the Test PyramidElias Nogueira
 
To study pcms pegasus erp cargo management system-release-7 from architectu...
To study pcms   pegasus erp cargo management system-release-7 from architectu...To study pcms   pegasus erp cargo management system-release-7 from architectu...
To study pcms pegasus erp cargo management system-release-7 from architectu...Shahzad
 
Maven TestNg frame work (1) (1)
Maven TestNg frame work (1) (1)Maven TestNg frame work (1) (1)
Maven TestNg frame work (1) (1)QA Programmer
 
Tizen Web Application Checker
Tizen Web Application CheckerTizen Web Application Checker
Tizen Web Application CheckerRyo Jin
 
Springboot2 postgresql-jpa-hibernate-crud-example
Springboot2 postgresql-jpa-hibernate-crud-exampleSpringboot2 postgresql-jpa-hibernate-crud-example
Springboot2 postgresql-jpa-hibernate-crud-exampleHyukSun Kwon
 
Open Source Software Testing Tools
Open Source Software Testing ToolsOpen Source Software Testing Tools
Open Source Software Testing ToolsVaruna Harshana
 
What’s new in Laravel 7.8?
What’s new in Laravel 7.8?What’s new in Laravel 7.8?
What’s new in Laravel 7.8?Techtic Solutions
 
Continuous Integration with TestMaker, Hudson, Jenkins, Bamboo
Continuous Integration with TestMaker, Hudson, Jenkins, BambooContinuous Integration with TestMaker, Hudson, Jenkins, Bamboo
Continuous Integration with TestMaker, Hudson, Jenkins, BambooClever Moe
 

What's hot (19)

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

Similar to Servlet LifeCycle Demo App

Online Form Submission App
Online Form Submission AppOnline Form Submission App
Online Form Submission AppPeeyush Ranjan
 
Top 10 Mistakes AngularJS Developers Make
Top 10 Mistakes AngularJS Developers MakeTop 10 Mistakes AngularJS Developers Make
Top 10 Mistakes AngularJS Developers MakeMark Meyer
 
Developing ASP.NET Applications Using the Model View Controller Pattern
Developing ASP.NET Applications Using the Model View Controller PatternDeveloping ASP.NET Applications Using the Model View Controller Pattern
Developing ASP.NET Applications Using the Model View Controller Patterngoodfriday
 
Haj 4328-java ee 7 overview
Haj 4328-java ee 7 overviewHaj 4328-java ee 7 overview
Haj 4328-java ee 7 overviewKevin Sutter
 
Spring Performance Gains
Spring Performance GainsSpring Performance Gains
Spring Performance GainsVMware Tanzu
 
Chapter 3 servlet & jsp
Chapter 3 servlet & jspChapter 3 servlet & jsp
Chapter 3 servlet & jspJafar Nesargi
 
ASP.NET AJAX Basics
ASP.NET AJAX BasicsASP.NET AJAX Basics
ASP.NET AJAX Basicspetrov
 
Wicket And Swing From One Codebase
Wicket And Swing From One CodebaseWicket And Swing From One Codebase
Wicket And Swing From One Codebasejcompagner
 
Станислав Сидоренко «DeviceHive Java Server – миграция на Spring Boot»
Станислав Сидоренко «DeviceHive Java Server – миграция на Spring Boot»Станислав Сидоренко «DeviceHive Java Server – миграция на Spring Boot»
Станислав Сидоренко «DeviceHive Java Server – миграция на Spring Boot»DataArt
 
Testing Microservices
Testing MicroservicesTesting Microservices
Testing MicroservicesAnil Allewar
 
I really need help on this question.Create a program that allows t.pdf
I really need help on this question.Create a program that allows t.pdfI really need help on this question.Create a program that allows t.pdf
I really need help on this question.Create a program that allows t.pdfamitbagga0808
 

Similar to Servlet LifeCycle Demo App (20)

Online Form Submission App
Online Form Submission AppOnline Form Submission App
Online Form Submission App
 
Java Servlets & JSP
Java Servlets & JSPJava Servlets & JSP
Java Servlets & JSP
 
C#on linux
C#on linuxC#on linux
C#on linux
 
Spring REST Request Validation
Spring REST Request ValidationSpring REST Request Validation
Spring REST Request Validation
 
Wt unit 3 server side technology
Wt unit 3 server side technologyWt unit 3 server side technology
Wt unit 3 server side technology
 
Wt unit 3 server side technology
Wt unit 3 server side technologyWt unit 3 server side technology
Wt unit 3 server side technology
 
Top 10 Mistakes AngularJS Developers Make
Top 10 Mistakes AngularJS Developers MakeTop 10 Mistakes AngularJS Developers Make
Top 10 Mistakes AngularJS Developers Make
 
Developing ASP.NET Applications Using the Model View Controller Pattern
Developing ASP.NET Applications Using the Model View Controller PatternDeveloping ASP.NET Applications Using the Model View Controller Pattern
Developing ASP.NET Applications Using the Model View Controller Pattern
 
Struts Interceptors
Struts InterceptorsStruts Interceptors
Struts Interceptors
 
Haj 4328-java ee 7 overview
Haj 4328-java ee 7 overviewHaj 4328-java ee 7 overview
Haj 4328-java ee 7 overview
 
Spring Performance Gains
Spring Performance GainsSpring Performance Gains
Spring Performance Gains
 
Chapter 3 servlet & jsp
Chapter 3 servlet & jspChapter 3 servlet & jsp
Chapter 3 servlet & jsp
 
ASP.NET AJAX Basics
ASP.NET AJAX BasicsASP.NET AJAX Basics
ASP.NET AJAX Basics
 
AJppt.pptx
AJppt.pptxAJppt.pptx
AJppt.pptx
 
Wicket And Swing From One Codebase
Wicket And Swing From One CodebaseWicket And Swing From One Codebase
Wicket And Swing From One Codebase
 
Vue js and Dyploma
Vue js and DyplomaVue js and Dyploma
Vue js and Dyploma
 
Станислав Сидоренко «DeviceHive Java Server – миграция на Spring Boot»
Станислав Сидоренко «DeviceHive Java Server – миграция на Spring Boot»Станислав Сидоренко «DeviceHive Java Server – миграция на Spring Boot»
Станислав Сидоренко «DeviceHive Java Server – миграция на Spring Boot»
 
Testing Microservices
Testing MicroservicesTesting Microservices
Testing Microservices
 
I really need help on this question.Create a program that allows t.pdf
I really need help on this question.Create a program that allows t.pdfI really need help on this question.Create a program that allows t.pdf
I really need help on this question.Create a program that allows t.pdf
 
Signal Framework
Signal FrameworkSignal Framework
Signal Framework
 

More from Peeyush Ranjan

More from Peeyush Ranjan (9)

Multiple Hyperlinks App
Multiple Hyperlinks AppMultiple Hyperlinks App
Multiple Hyperlinks App
 
Scrollable Test App
Scrollable Test AppScrollable Test App
Scrollable Test App
 
Scrollable Demo App
Scrollable Demo AppScrollable Demo App
Scrollable Demo App
 
Cursor Demo App
Cursor Demo AppCursor Demo App
Cursor Demo App
 
Batch processing Demo
Batch processing DemoBatch processing Demo
Batch processing Demo
 
Transaction Management Tool
Transaction Management ToolTransaction Management Tool
Transaction Management Tool
 
Net Beans Codes for Student Portal
Net Beans Codes for Student PortalNet Beans Codes for Student Portal
Net Beans Codes for Student Portal
 
TextSearch
TextSearchTextSearch
TextSearch
 
DBTool
DBToolDBTool
DBTool
 

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>