SlideShare ist ein Scribd-Unternehmen logo
1 von 34
Downloaden Sie, um offline zu lesen
JAVA SERVLETTECHNOLOGY
PREPARED BY: MINAL MANIAR,ASSISTANT PROFESSOR, CSPIT, CHARUSAT
INTRODUCTION
 Shortly after the Web began to be used for delivering services, service providers
recognized the need for dynamic content.
 Applets, one of the earliest attempts toward this goal.
 At the same time, developers also investigated using the server platform for the same
purpose. Initially, Common Gateway Interface (CGI) server-side scripts were the
main technology used to generate dynamic content.
 Although widely used, CGI scripting technology had many shortcomings.
CGI(COMMMON GATEWAY INTERFACE)
DISADVANTAGES OF CGI TECHNOLOGY
 Platform Dependent
 If number of clients increases, it takes more time for sending response. – Lack of
Scalability
 For each request, it starts a process and Web server is limited to start processes.
 It uses platform dependent language e.g. C, C++, perl.
 To address these limitations, Java Servlet technology was created as a portable
way to provide dynamic, user-oriented content.
INTRODUCTION TO SERVLET
JAVA SERVLETTECHNOLOGY
 Servlet technology is used to create web application (resides at server side and
generates dynamic web page).
 Servlet can be described in many ways, depending on the context.
 Servlet is a technology i.e. used to create web application.
 Servlet is an API that provides many interfaces and classes including documentations.
 Servlet is an interface that must be implemented for creating any servlet.
 Servlet is a class that extends the capabilities of the servers and responds to the
incoming requests. It can respond to any type of requests.
 Servlet is a web component that is deployed on the server to create dynamic web
page.
WHAT IS A SERVLET ?
 “A servlet is a Java programming language class used to extend the
capabilities of servers that host applications accessed by means of a
request-response programming model.”
 Although servlets can respond to any type of request, they are
commonly used to extend the applications hosted by web servers. For
such applications, Java Servlet technology defines HTTP-specific servlet
classes.
WHAT IS A SERVLET ?
 javax .servlet and javax.servlet.http packages provide interfaces and classes for
writing Servlet
 All Servlets must implement the Servlet interface, which defines lifecycle methods.
 Javax.servlet package contains many interfaces and classes that are used by the
servlet or web container.
 javax.servlet.http package contains interfaces and classes that are responsible for
http requests only.
ADVANTAGES OF SERVLET OVER CGI
 Better Performance
 Portability
 Robust
 Secure
WEB TERMINOLOGY
 Website – Static and Dynamic
 HTTP, HTTP Request
 GET, POST
 Servlet Container
 Web Server and Application Server
SERVLET CONTAINER
 The Servlet Container performs many operations that are given below:
 Life Cycle Management
 Multithreaded support
 Object Pooling
 Security
WEB SERVER
 Web server contains only web or servlet container. It can be used for servlet, jsp,
struts, jsf etc. It can't be used for EJB.
 It is a computer where the web content can be stored.
 web server can be used to host the web sites but there also used some other web
servers also such as FTP, email, storage, gaming etc.
 Examples of Web Servers are: ApacheTomcat, IIS
 It can respond to the client request in either of the following two possible ways:
 Generating response by using the script and communicating with database.
 Sending file to the client associated with the requested URL.
ENVIRONMENT SETUP - ECLIPSE
 Configure dynamic Web Project in Eclipse IDE
 Set up Apache Tomcat Server instance in Eclipse IDE
 Set up build path of project; add all Servlet and JSP Libraries (Add Library – servlet-
api.jar)
 Add JDBC driver JAR for MySQL – Paste Under Lib folder of your workspace and
Add JAR from Properties
 https://dev.mysql.com/downloads/connector/j/5.1.html
 Deploy and run the Project on the Server – Right click Run As Server
 WAR file - tomcat understands onlyWAR
 Deploy WAR external to Eclipse IDE
DEPLOY EXTERNAL TO ECLIPSE
 Right click project and export it to generateWAR file
 PutWAR file inTomcat – webapps folder to deploy your project
 Go to <Tomcat_Home>bin in command prompt
 Start Server : startup.bat
ALTERNATIVESTO SETUP APPLICATION
 Maven or Gradle – Set up the entire project structure and configure build path with
all necessary Library
 JBoss,WebLogic, GlassFish or ant Java EE – Compliant contianers/servers for hosting
the application
 Ask build tool itself to deploy and run the project on server
 NetBeans or IntelliJ IDE for development
 Any other relational database
PROJECT APPLICATION SETUP
 Implements Model->View-> Controller(MVC) architecture
 View – JSP or HTML files
 Controller – Servlet classes that intercept request and prepare
response
 Model – data access object (DAO) classes that talk to the database
 Copy css , html and images folder under Web Content in your
project
PROJECT APPLICATION SETUP : DATABASE SETUP FOR APPLICATION
 Schema name of your choice – hplus
 MySQL database server
 Following tables have been used:
 Users – to store all user information
 Products – to store all product related information
 Orders - to store order history of a particular user
 hplus.sql :You can import – run this script in MySQL server
TYPES OF HTTP REQUEST
GET – gets information from server:Idempotent – Wouldn’t change anything on server side if request is sent out multiple times
POST – processes information on server
PUT – Uploads a resource on server
DELETE - deletes a resource on server
HEAD – same as GET , but returns only the headers
OPTIONS – helps trace what HTTP methods work on server
FORWARDING IN SERVLET
 The RequestDispatcher interface provides the facility of dispatching the request to
another resource it may be html, servlet or jsp.
 This interface can also be used to include the content of another resource also.
 There are two methods defined in the RequestDispatcher interface.
FORWARD() METHOD
 Response of second servlet
is sent to the client.
Response of the first servlet
is not displayed to the user.
FORWARD() METHOD
 Response of second servlet
is included in the response
of the first servlet that is
being sent to the client.
SEND REDIRECT IN SERVLET
 This method is used to redirect response to another resource,
 It may be servlet
 JSP or
 html file.
 This interface can also be used to include the content of another resource.
FORWARD()VS SENDREDIRECT()
 comparison
SERVLETCONFIG INTERFACE
 An object of ServletConfig is created by the web container for each servlet.
 This object can be used to get configuration information from web.xml file.
 The core advantage of ServletConfig is that you don't need to edit the servlet file if
information is modified from the web.xml file.
 public ServletConfig getServletConfig(); //syntax
SERVLETCONFIG INTERFACE
 ServletConfig config=getServletConfig();
EXAMPLE OF SERVLETCONFIG TO GET INITIALIZATION PARAMETER
WEB.XML
EXAMPLE OF SERVLETCONFIG TO GET ALL THE INITIALIZATION
PARAMETERS
SERVLETCONTEXT INTERFACE
 An object of ServletContext is created by the web container at time of deploying the project.
 This object can be used to get configuration information from web.xml file.
 There is only one ServletContext object per web application.
 If any information is shared to many servlet, it is better to provide it from the web.xml file using
the <context-param> element.
 The object of ServletContext provides an interface between the container and servlet.
 The ServletContext object can be used to get configuration information from the web.xml file.
 The ServletContext object can be used to set, get or remove attribute from the web.xml file.
 The ServletContext object can be used to provide inter-application communication.
TO GET THE OBJECT OF SERVLETCONTEXT INTERFACE
 getServletContext() method of ServletConfig interface returns the object of ServletContext.
 getServletContext() method of GenericServlet class returns the object of ServletContext.
 Examples
 //We can get the ServletContext object from ServletConfig object
 ServletContext application=getServletConfig().getServletContext();
 //Another convenient way to get the ServletContext object
 ServletContext application=getServletContext();
EXAMPLE OF SERVLETCONTEXT TO GETTHE INITIALIZATION
PARAMETER
Web.xml
COMPARISON
COMPARISON
REFERENCES
 https://docs.oracle.com/javaee/7/tutorial/
 https://www.java4s.com
 https://www.lynda.com
 https://javarevisited.blogspot.com
 https://www.javatpoint.com/

Weitere ähnliche Inhalte

Was ist angesagt?

Chapter 3 servlet & jsp
Chapter 3 servlet & jspChapter 3 servlet & jsp
Chapter 3 servlet & jspJafar Nesargi
 
An Introduction To Java Web Technology
An Introduction To Java Web TechnologyAn Introduction To Java Web Technology
An Introduction To Java Web Technologyvikram singh
 
Servlet/JSP course chapter 1: Introduction to servlets
Servlet/JSP course chapter 1: Introduction to servletsServlet/JSP course chapter 1: Introduction to servlets
Servlet/JSP course chapter 1: Introduction to servletsJavaEE Trainers
 
Java servlets
Java servletsJava servlets
Java servletslopjuan
 
1 java servlets and jsp
1   java servlets and jsp1   java servlets and jsp
1 java servlets and jspAnkit Minocha
 
Java EE 01-Servlets and Containers
Java EE 01-Servlets and ContainersJava EE 01-Servlets and Containers
Java EE 01-Servlets and ContainersFernando Gil
 
JAVA Servlets
JAVA ServletsJAVA Servlets
JAVA Servletsdeepak kumar
 
Core web application development
Core web application developmentCore web application development
Core web application developmentBahaa Farouk
 
java servlet and servlet programming
java servlet and servlet programmingjava servlet and servlet programming
java servlet and servlet programmingKumar
 
Servlet and JSP
Servlet and JSPServlet and JSP
Servlet and JSPGary Yeh
 

Was ist angesagt? (20)

Chapter 3 servlet & jsp
Chapter 3 servlet & jspChapter 3 servlet & jsp
Chapter 3 servlet & jsp
 
An Introduction To Java Web Technology
An Introduction To Java Web TechnologyAn Introduction To Java Web Technology
An Introduction To Java Web Technology
 
Servlets
ServletsServlets
Servlets
 
Servlet/JSP course chapter 1: Introduction to servlets
Servlet/JSP course chapter 1: Introduction to servletsServlet/JSP course chapter 1: Introduction to servlets
Servlet/JSP course chapter 1: Introduction to servlets
 
Jsp servlets
Jsp servletsJsp servlets
Jsp servlets
 
JDBC
JDBCJDBC
JDBC
 
Java servlets
Java servletsJava servlets
Java servlets
 
Java servlets
Java servletsJava servlets
Java servlets
 
1 java servlets and jsp
1   java servlets and jsp1   java servlets and jsp
1 java servlets and jsp
 
Java EE 01-Servlets and Containers
Java EE 01-Servlets and ContainersJava EE 01-Servlets and Containers
Java EE 01-Servlets and Containers
 
JAVA Servlets
JAVA ServletsJAVA Servlets
JAVA Servlets
 
Core web application development
Core web application developmentCore web application development
Core web application development
 
Servlets
ServletsServlets
Servlets
 
Servlets
ServletsServlets
Servlets
 
Java Servlets
Java ServletsJava Servlets
Java Servlets
 
Servlets
ServletsServlets
Servlets
 
java servlet and servlet programming
java servlet and servlet programmingjava servlet and servlet programming
java servlet and servlet programming
 
Servlet
Servlet Servlet
Servlet
 
Servlets
ServletsServlets
Servlets
 
Servlet and JSP
Servlet and JSPServlet and JSP
Servlet and JSP
 

Ă„hnlich wie Java servlet technology

UNIT-3 Servlet
UNIT-3 ServletUNIT-3 Servlet
UNIT-3 Servletssbd6985
 
Java Servlet
Java ServletJava Servlet
Java ServletYoga Raja
 
Jsp and Servlets
Jsp and ServletsJsp and Servlets
Jsp and ServletsRaghu nath
 
Advance Java Topics (J2EE)
Advance Java Topics (J2EE)Advance Java Topics (J2EE)
Advance Java Topics (J2EE)slire
 
Programming Server side with Sevlet
 Programming Server side with Sevlet  Programming Server side with Sevlet
Programming Server side with Sevlet backdoor
 
Unit5 servlets
Unit5 servletsUnit5 servlets
Unit5 servletsPraveen Yadav
 
Servlets 3.0 - Asynchronous, Easy, Extensible @ Silicon Valley Code Camp 2010
Servlets 3.0 - Asynchronous, Easy, Extensible @ Silicon Valley Code Camp 2010Servlets 3.0 - Asynchronous, Easy, Extensible @ Silicon Valley Code Camp 2010
Servlets 3.0 - Asynchronous, Easy, Extensible @ Silicon Valley Code Camp 2010Arun Gupta
 
Ppt for Online music store
Ppt for Online music storePpt for Online music store
Ppt for Online music storeADEEBANADEEM
 
SERVER SIDE PROGRAMMING
SERVER SIDE PROGRAMMINGSERVER SIDE PROGRAMMING
SERVER SIDE PROGRAMMINGPrabu U
 
Servlet in java , java servlet , servlet servlet and CGI, API
Servlet in java , java servlet , servlet servlet and CGI, APIServlet in java , java servlet , servlet servlet and CGI, API
Servlet in java , java servlet , servlet servlet and CGI, APIPRIYADARSINISK
 
JavaEE6 my way
JavaEE6 my wayJavaEE6 my way
JavaEE6 my wayNicola Pedot
 
Learning ASP.NET 5 and MVC 6
Learning ASP.NET 5 and MVC 6Learning ASP.NET 5 and MVC 6
Learning ASP.NET 5 and MVC 6Ido Flatow
 
Wt unit 3
Wt unit 3 Wt unit 3
Wt unit 3 team11vgnt
 
Java Servlet Programming under Ubuntu Linux by Tushar B Kute
Java Servlet Programming under Ubuntu Linux by Tushar B KuteJava Servlet Programming under Ubuntu Linux by Tushar B Kute
Java Servlet Programming under Ubuntu Linux by Tushar B KuteTushar B Kute
 
sveltekit-en.pdf
sveltekit-en.pdfsveltekit-en.pdf
sveltekit-en.pdfssuser65180a
 
JEE Course - The Web Tier
JEE Course - The Web TierJEE Course - The Web Tier
JEE Course - The Web Tierodedns
 
Web container and Apache Tomcat
Web container and Apache TomcatWeb container and Apache Tomcat
Web container and Apache TomcatAuwal Amshi
 

Ă„hnlich wie Java servlet technology (20)

UNIT-3 Servlet
UNIT-3 ServletUNIT-3 Servlet
UNIT-3 Servlet
 
Java Servlet
Java ServletJava Servlet
Java Servlet
 
Jsp and Servlets
Jsp and ServletsJsp and Servlets
Jsp and Servlets
 
Advance Java Topics (J2EE)
Advance Java Topics (J2EE)Advance Java Topics (J2EE)
Advance Java Topics (J2EE)
 
Programming Server side with Sevlet
 Programming Server side with Sevlet  Programming Server side with Sevlet
Programming Server side with Sevlet
 
Unit5 servlets
Unit5 servletsUnit5 servlets
Unit5 servlets
 
Ecom 1
Ecom 1Ecom 1
Ecom 1
 
Servlets 3.0 - Asynchronous, Easy, Extensible @ Silicon Valley Code Camp 2010
Servlets 3.0 - Asynchronous, Easy, Extensible @ Silicon Valley Code Camp 2010Servlets 3.0 - Asynchronous, Easy, Extensible @ Silicon Valley Code Camp 2010
Servlets 3.0 - Asynchronous, Easy, Extensible @ Silicon Valley Code Camp 2010
 
Ppt for Online music store
Ppt for Online music storePpt for Online music store
Ppt for Online music store
 
SERVER SIDE PROGRAMMING
SERVER SIDE PROGRAMMINGSERVER SIDE PROGRAMMING
SERVER SIDE PROGRAMMING
 
Servlet in java , java servlet , servlet servlet and CGI, API
Servlet in java , java servlet , servlet servlet and CGI, APIServlet in java , java servlet , servlet servlet and CGI, API
Servlet in java , java servlet , servlet servlet and CGI, API
 
JavaEE6 my way
JavaEE6 my wayJavaEE6 my way
JavaEE6 my way
 
AJppt.pptx
AJppt.pptxAJppt.pptx
AJppt.pptx
 
Learning ASP.NET 5 and MVC 6
Learning ASP.NET 5 and MVC 6Learning ASP.NET 5 and MVC 6
Learning ASP.NET 5 and MVC 6
 
Wt unit 3
Wt unit 3 Wt unit 3
Wt unit 3
 
Java Servlet Programming under Ubuntu Linux by Tushar B Kute
Java Servlet Programming under Ubuntu Linux by Tushar B KuteJava Servlet Programming under Ubuntu Linux by Tushar B Kute
Java Servlet Programming under Ubuntu Linux by Tushar B Kute
 
sveltekit-en.pdf
sveltekit-en.pdfsveltekit-en.pdf
sveltekit-en.pdf
 
JEE Course - The Web Tier
JEE Course - The Web TierJEE Course - The Web Tier
JEE Course - The Web Tier
 
Servlet by Rj
Servlet by RjServlet by Rj
Servlet by Rj
 
Web container and Apache Tomcat
Web container and Apache TomcatWeb container and Apache Tomcat
Web container and Apache Tomcat
 

Mehr von Minal Maniar

Exception handling
Exception handlingException handling
Exception handlingMinal Maniar
 
Java8 features
Java8 featuresJava8 features
Java8 featuresMinal Maniar
 
Multi t hreading_14_10
Multi t hreading_14_10Multi t hreading_14_10
Multi t hreading_14_10Minal Maniar
 
Class method object
Class method objectClass method object
Class method objectMinal Maniar
 
Object oriented thinking
Object oriented thinkingObject oriented thinking
Object oriented thinkingMinal Maniar
 
2 class use case
2 class use case2 class use case
2 class use caseMinal Maniar
 
1 modeling concepts
1 modeling concepts1 modeling concepts
1 modeling conceptsMinal Maniar
 
5 collection framework
5 collection framework5 collection framework
5 collection frameworkMinal Maniar
 
3 interaction and_state_modeling
3 interaction and_state_modeling3 interaction and_state_modeling
3 interaction and_state_modelingMinal Maniar
 
modeling concepts
modeling conceptsmodeling concepts
modeling conceptsMinal Maniar
 
modeling concepts
modeling conceptsmodeling concepts
modeling conceptsMinal Maniar
 

Mehr von Minal Maniar (15)

Exception handling
Exception handlingException handling
Exception handling
 
Java ce241
Java ce241Java ce241
Java ce241
 
Java8 features
Java8 featuresJava8 features
Java8 features
 
Multi t hreading_14_10
Multi t hreading_14_10Multi t hreading_14_10
Multi t hreading_14_10
 
Io
IoIo
Io
 
Class method object
Class method objectClass method object
Class method object
 
Object oriented thinking
Object oriented thinkingObject oriented thinking
Object oriented thinking
 
2 class use case
2 class use case2 class use case
2 class use case
 
Oop java
Oop javaOop java
Oop java
 
1 modeling concepts
1 modeling concepts1 modeling concepts
1 modeling concepts
 
5 collection framework
5 collection framework5 collection framework
5 collection framework
 
4 sdlc
4 sdlc4 sdlc
4 sdlc
 
3 interaction and_state_modeling
3 interaction and_state_modeling3 interaction and_state_modeling
3 interaction and_state_modeling
 
modeling concepts
modeling conceptsmodeling concepts
modeling concepts
 
modeling concepts
modeling conceptsmodeling concepts
modeling concepts
 

KĂĽrzlich hochgeladen

Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontologyjohnbeverley2021
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamUiPathCommunity
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...apidays
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityWSO2
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Angeliki Cooney
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Zilliz
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxRemote DBA Services
 

KĂĽrzlich hochgeladen (20)

Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 

Java servlet technology

  • 1. JAVA SERVLETTECHNOLOGY PREPARED BY: MINAL MANIAR,ASSISTANT PROFESSOR, CSPIT, CHARUSAT
  • 2. INTRODUCTION  Shortly after the Web began to be used for delivering services, service providers recognized the need for dynamic content.  Applets, one of the earliest attempts toward this goal.  At the same time, developers also investigated using the server platform for the same purpose. Initially, Common Gateway Interface (CGI) server-side scripts were the main technology used to generate dynamic content.  Although widely used, CGI scripting technology had many shortcomings.
  • 4. DISADVANTAGES OF CGI TECHNOLOGY  Platform Dependent  If number of clients increases, it takes more time for sending response. – Lack of Scalability  For each request, it starts a process and Web server is limited to start processes.  It uses platform dependent language e.g. C, C++, perl.  To address these limitations, Java Servlet technology was created as a portable way to provide dynamic, user-oriented content.
  • 6. JAVA SERVLETTECHNOLOGY  Servlet technology is used to create web application (resides at server side and generates dynamic web page).  Servlet can be described in many ways, depending on the context.  Servlet is a technology i.e. used to create web application.  Servlet is an API that provides many interfaces and classes including documentations.  Servlet is an interface that must be implemented for creating any servlet.  Servlet is a class that extends the capabilities of the servers and responds to the incoming requests. It can respond to any type of requests.  Servlet is a web component that is deployed on the server to create dynamic web page.
  • 7. WHAT IS A SERVLET ?  “A servlet is a Java programming language class used to extend the capabilities of servers that host applications accessed by means of a request-response programming model.”  Although servlets can respond to any type of request, they are commonly used to extend the applications hosted by web servers. For such applications, Java Servlet technology defines HTTP-specific servlet classes.
  • 8. WHAT IS A SERVLET ?  javax .servlet and javax.servlet.http packages provide interfaces and classes for writing Servlet  All Servlets must implement the Servlet interface, which defines lifecycle methods.  Javax.servlet package contains many interfaces and classes that are used by the servlet or web container.  javax.servlet.http package contains interfaces and classes that are responsible for http requests only.
  • 9. ADVANTAGES OF SERVLET OVER CGI  Better Performance  Portability  Robust  Secure
  • 10. WEB TERMINOLOGY  Website – Static and Dynamic  HTTP, HTTP Request  GET, POST  Servlet Container  Web Server and Application Server
  • 11. SERVLET CONTAINER  The Servlet Container performs many operations that are given below:  Life Cycle Management  Multithreaded support  Object Pooling  Security
  • 12. WEB SERVER  Web server contains only web or servlet container. It can be used for servlet, jsp, struts, jsf etc. It can't be used for EJB.  It is a computer where the web content can be stored.  web server can be used to host the web sites but there also used some other web servers also such as FTP, email, storage, gaming etc.  Examples of Web Servers are: ApacheTomcat, IIS  It can respond to the client request in either of the following two possible ways:  Generating response by using the script and communicating with database.  Sending file to the client associated with the requested URL.
  • 13. ENVIRONMENT SETUP - ECLIPSE  Configure dynamic Web Project in Eclipse IDE  Set up Apache Tomcat Server instance in Eclipse IDE  Set up build path of project; add all Servlet and JSP Libraries (Add Library – servlet- api.jar)  Add JDBC driver JAR for MySQL – Paste Under Lib folder of your workspace and Add JAR from Properties  https://dev.mysql.com/downloads/connector/j/5.1.html  Deploy and run the Project on the Server – Right click Run As Server  WAR file - tomcat understands onlyWAR  Deploy WAR external to Eclipse IDE
  • 14. DEPLOY EXTERNAL TO ECLIPSE  Right click project and export it to generateWAR file  PutWAR file inTomcat – webapps folder to deploy your project  Go to <Tomcat_Home>bin in command prompt  Start Server : startup.bat
  • 15. ALTERNATIVESTO SETUP APPLICATION  Maven or Gradle – Set up the entire project structure and configure build path with all necessary Library  JBoss,WebLogic, GlassFish or ant Java EE – Compliant contianers/servers for hosting the application  Ask build tool itself to deploy and run the project on server  NetBeans or IntelliJ IDE for development  Any other relational database
  • 16. PROJECT APPLICATION SETUP  Implements Model->View-> Controller(MVC) architecture  View – JSP or HTML files  Controller – Servlet classes that intercept request and prepare response  Model – data access object (DAO) classes that talk to the database  Copy css , html and images folder under Web Content in your project
  • 17. PROJECT APPLICATION SETUP : DATABASE SETUP FOR APPLICATION  Schema name of your choice – hplus  MySQL database server  Following tables have been used:  Users – to store all user information  Products – to store all product related information  Orders - to store order history of a particular user  hplus.sql :You can import – run this script in MySQL server
  • 18. TYPES OF HTTP REQUEST GET – gets information from server:Idempotent – Wouldn’t change anything on server side if request is sent out multiple times POST – processes information on server PUT – Uploads a resource on server DELETE - deletes a resource on server HEAD – same as GET , but returns only the headers OPTIONS – helps trace what HTTP methods work on server
  • 19. FORWARDING IN SERVLET  The RequestDispatcher interface provides the facility of dispatching the request to another resource it may be html, servlet or jsp.  This interface can also be used to include the content of another resource also.  There are two methods defined in the RequestDispatcher interface.
  • 20. FORWARD() METHOD  Response of second servlet is sent to the client. Response of the first servlet is not displayed to the user.
  • 21. FORWARD() METHOD  Response of second servlet is included in the response of the first servlet that is being sent to the client.
  • 22. SEND REDIRECT IN SERVLET  This method is used to redirect response to another resource,  It may be servlet  JSP or  html file.  This interface can also be used to include the content of another resource.
  • 24. SERVLETCONFIG INTERFACE  An object of ServletConfig is created by the web container for each servlet.  This object can be used to get configuration information from web.xml file.  The core advantage of ServletConfig is that you don't need to edit the servlet file if information is modified from the web.xml file.  public ServletConfig getServletConfig(); //syntax
  • 25. SERVLETCONFIG INTERFACE  ServletConfig config=getServletConfig();
  • 26. EXAMPLE OF SERVLETCONFIG TO GET INITIALIZATION PARAMETER
  • 28. EXAMPLE OF SERVLETCONFIG TO GET ALL THE INITIALIZATION PARAMETERS
  • 29. SERVLETCONTEXT INTERFACE  An object of ServletContext is created by the web container at time of deploying the project.  This object can be used to get configuration information from web.xml file.  There is only one ServletContext object per web application.  If any information is shared to many servlet, it is better to provide it from the web.xml file using the <context-param> element.  The object of ServletContext provides an interface between the container and servlet.  The ServletContext object can be used to get configuration information from the web.xml file.  The ServletContext object can be used to set, get or remove attribute from the web.xml file.  The ServletContext object can be used to provide inter-application communication.
  • 30. TO GET THE OBJECT OF SERVLETCONTEXT INTERFACE  getServletContext() method of ServletConfig interface returns the object of ServletContext.  getServletContext() method of GenericServlet class returns the object of ServletContext.  Examples  //We can get the ServletContext object from ServletConfig object  ServletContext application=getServletConfig().getServletContext();  //Another convenient way to get the ServletContext object  ServletContext application=getServletContext();
  • 31. EXAMPLE OF SERVLETCONTEXT TO GETTHE INITIALIZATION PARAMETER Web.xml
  • 34. REFERENCES  https://docs.oracle.com/javaee/7/tutorial/  https://www.java4s.com  https://www.lynda.com  https://javarevisited.blogspot.com  https://www.javatpoint.com/