SlideShare a Scribd company logo
JAVA
Part III
Java Enterprise Edition
The Java EE is complete platform for developing multi-tiered distributed applications. It consists of:
• The Java Virtual Machine (JVM).
• The Java SE APIs (SE APIs).
• The Java EE Application Server.
• The Java EE APIs (EE APIs).
 Specifications of standard API
 Defined by the Java Community Process (JCP)
 Java Specification Requests (JSRs): proposed and final specifications
 Different implementation of same API
 Example: JPA is implemented by Eclipselink, OpenJPA, Hibernate
 Certifications
 Architecture pattern
 Large scale
 Multi-tiers (Presentation Logic, Business Logic, Persistence)
 Scalable
 Reliable
 Secure
Java EE architecture
Client
Database
EJB Container
Web Container
Application
Client
Application
Client
Web Browser
Web Browser
Enterprise
Bean
Servlet JSP Page
Java EE Server
Enterprise
Bean
Enterprise
Bean
JSP Page
Servlet
EJB – Enterprise Java Beans
1. What is a bean?
• Beans are business logic components that implement a standard interface through which the bean is hooked into
the bean container (= runtime object for bean).
• A Java class implementing one of the standard bean interfaces is a bean.
• Beans can be accessed remotely, usually from a client tier.
Bean
Bean
container
EJB
Why EJB?
Common concerns in different applications lead to re-implementing the same functionality for business logic components.
Examples of common functionality:
- Persistence
- Transactions
- Security
- Runtime and lifecycle management (create, start, stop and delete component)
EJB is a framework that provides the following services to applications:
- Persistence
- Transaction processing
- Concurrency control (each client accesses its own bean instance)
- Events using JMS (Java Messaging Service)
- Naming and directory services via JNDI (Java Naming and Directory Interface)
- Security using JAAS (Java Authentication and Authorization Service)
- Deployment of software components to a server host
- Remote procedure calls via RMI (RMI over IIOP)
- Exposing business functionality via web services
Business
logic
Front end
(protocol, GUI)
Backend
(DB)
Servlet
 Java Servlet is a java object file developed as a component and
runs on the server.
 Servlets are programs that run on a Web or application server
and act as a middle layer between a request coming from a Web
browser or other HTTP client and databases or applications on
the HTTP server
Servlets is a component can be invoked from HTML.
Note:
 Servlets cannot run independently as a main application
like the java applet, the servlet does not have main method.
 Servlet do not display a graphical interface to the user.
 A servlet’s work is done at the server and only the results
of the servlet’s processing are returned to the client in the
form of HTML.
 A Servlet is a Java technology-based Web component,
managed by a container that generates dynamic content.
 Like other Java technology-based components, Servlets
are platform-independent Java classes that are compiled
to platform-neutral byte code that can be loaded
dynamically into and run by a Java technology-enabled
Web server.
Servlet
Advantages of Servlet
 Platform Independence:
Servlets are written entirely in java so these are platform
independent.
Servlets can run on any Servlet enabled web server.
 Performance
Due to interpreted nature of java, programs written in java are slow.
But the java Servlets runs very fast. These are due to the way Servlets run on web
server.
For any program initialization takes significant amount of time. But in case of
Servlets initialization takes place first time it receives a request and remains in
memory till times out or server shut downs.
 Extensibility
Java Servlets are developed in java which is robust, well- designed and
object oriented language which can be extended or polymorphed into new
objects.
So the java Servlets take all these advantages and can be extended from
existing class to provide the ideal solutions.
 4. Safety Java provides very good safety features like memory
management, exception handling etc. Servlets inherits all these
features and emerged as a very powerful web server extension.
 5. Secure Servlets are server side components, so it inherits the
security provided by the web server. Servlets are also benefited with
Java Security Manager.
JSP
 JSP is one of the most powerful, easy-to-use, and
fundamental tools in a Web-site developer's toolbox.
 JSP combines HTML and XML with Java servlet (server
application extension) and JavaBeans technologies to create
a highly productive environment for developing and deploying
reliable, interactive, high-performance platform- independent
Web sites.
 JSP facilitates the creation of dynamic content on the server.
 It is part of the Java platform's integrated
solution for server-side programming, which
provides a portable alternative to other server-
side technologies, such as CGI.
 JSP integrates numerous Java application
technologies, such as Java servlet, JavaBeans,
JDBC, and Enterprise JavaBeans.
 It also separates information presentation from
application logic and fosters a reusable
component model of programming.
Advantages of JSP
 Servlet use println statements for printing an HTML
document which is usually very difficult to use. JSP has no
such tedious task to maintain.
 JSP needs no compilation, CLASSPATH setting and
packaging.
 In a JSP page visual content and logic are seperated,
which is not possible in a servlet.
 There is automatic deployment of a JSP; recompilation is
done automatically when changes are made to JSP pages.
 Usually with JSP, Java Beans and custom tags web
application is simplified.
Fundamental JSP Tags
 JSP tags are an important syntax element of Java Server
Pages which start with "<%" and end with "%>" just like
HTML tags. JSP tags normally have a "start tag", a "tag
body" and an "end tag". JSP tags can either be predefined
tags or loaded from an external tag library.
 Fundamental tags used in Java Server Pages are classified
into the following categories:-
 Declaration tag
 Expression tag
 Directive tag
 Scriptlet tag
 Comments
HTTP- Hyper Text Transfer Protocol
• Protocol: A Protocol is a standard procedure for defining and
regulating communication. For example TCP,UDP, HTTP etc.
• HTTP is the foundation of data communication for the World Wide
Web.
• The HTTP is the Web’s application-layer protocol for transferring
various forms of data between server and client like plaintext,
hypertext, image, videos and sounds .
How HTTP Works?
• The Hypertext Transfer Protocol (HTTP) is designed to enable
communications between clients and servers.
• HTTP works as a request-response protocol between a client and
server.
• Example: A client (browser) sends an HTTP request to the server; then
the server returns a response to the client. The response contains
status information about the request and may also contain the
requested content.
HTTP Methods
•GET
•POST
•PUT
•HEAD
•DELETE
•PATCH
•OPTIONS
The two most common HTTP methods are: GET
and POST.
How HTTP Works?
Suppose client wants to visit www.yahoo.com
How HTTP Works? (CONT.)
How HTTP Works? (CONT.)
How HTTP Works? (CONT.)
How HTTP Works? (CONT.)
Http Get Request
GET is used to request data from a specified resource.
GET is one of the most common HTTP methods.
Note that the query string (name/value pairs) is sent in the URL of a GET request:
/test/demo_form.php?name1=value1&name2=value2
Some other notes on GET requests:
•GET requests can be cached
•GET requests remain in the browser history
•GET requests can be bookmarked
•GET requests should never be used when dealing with sensitive data
•GET requests have length restrictions
•GET requests are only used to request data (not modify)
Http Post Request
The POST Method
POST is used to send data to a server to create/update a resource.
The data sent to the server with POST is stored in the request body of the HTTP request:
POST /test/demo_form.php HTTP/1.1
Host: w3schools.com
name1=value1&name2=value2
POST is one of the most common HTTP methods.
Some other notes on POST requests:
•POST requests are never cached
•POST requests do not remain in the browser history
•POST requests cannot be bookmarked
•POST requests have no restrictions on data length
HTML- Hyper Text Markup Language
What is HTML?
• HTML is a language for describing web pages.
• HTML is not a programming language, it is a markup language
• A markup language is a set of markup tags
• HTML uses markup tags to describe web pages
HTML Tags
• HTML markup tags are usually called HTML tags
• HTML tags are keywords surrounded by angle brackets like
<html>
• HTML tags normally come in pairs like <b> and </b>
• The first tag in a pair is the start tag, the second tag is the end tag
• Start and end tags are also called opening tags and closing tags .
URL
 URL stands for Uniform Resource Locator is the global address of documents and other resources on the World
Wide Web. Its main purpose is to identify the location of a document and other resources available on the
internet, and specify the mechanism for accessing it through a web browser.
 A URL (Uniform Resource Locator) is a unique identifier used to locate a resource on the internet. It is also
referred to as a web address.
 URLs consist of multiple parts including a protocol and domain name that tell a web browser how and where
to retrieve a resource
 The URL contains the name of the protocol needed to access a resource, as well as a resource name
Containers
The application server provides the runtime platform in the form of containers. A container is a component of the
application server that manages a specific type of components and provide them with all the needed services and
Java EE API implementation. The two types of containers are:
-Business Container
The business container is responsible for managing business components and providing them with runtime
services like: RMI communication, database manipulation, transaction services, etc.
-Web Container
The web container is responsible for managing web components and providing them with runtime services
like: HTTP communication, database manipulation, etc.
Servlet Life Cycle & Life Cycles Methods
• Init () Method
• Service () Method
• Destroy() method
Init () Method:-
 During initialization stage of the Servlet life cycle, the web container initializes the servlet
instance by calling the init() method.
 The container passes an object implementing the ServletConfig interface via the init()
method.
 This configuration object allows the servlet to access name- value initialization parameters
from the web application.
• Service () Method:-
◦ After initialization, the servlet can service client requests. each request is serviced in
its own separate thread.
◦ The Web container calls the service() method of the servlet for every
request.
◦ The service() method determines the kind of request being made and dispatches it to
an appropriate method to handle the request.
◦ The developer of the servlet must provide an implementation for these methods. If a
request for a method that is not implemented by the servlet is made, the method of the
parent class is called, typically resulting in an error being returned to the requester.
• Destroy() method:-
◦ Finally, the Web container calls the destroy() method that takes the servlet out of
service. The destroy() method, like init(), is called only once in the lifecycle of a servlet.
HTTP Request
HTTP Response
Difference Between Get And Post
GET POST
BACK button/Reload Harmless Data will be re-submitted (the browser should alert the
user that the data are about to be re-submitted)
Bookmarked Can be bookmarked Cannot be bookmarked
Cached Can be cached Not cached
Encoding type application/x-www-form-urlencoded application/x-www-form-urlencoded or
multipart/form-data. Use multipart encoding for binary
data
History Parameters remain in browser history Parameters are not saved in browser history
Restrictions on data length Yes, when sending data, the GET method adds the data
to the URL; and the length of a URL is limited
(maximum URL length is 2048 characters)
No restrictions
Restrictions on data type Only ASCII characters allowed No restrictions. Binary data is also allowed
Security GET is less secure compared to POST because data sent
is part of the URL
Never use GET when sending passwords or other
sensitive information!
POST is a little safer than GET because the parameters
are not stored in browser history or in web server logs
Visibility Data is visible to everyone in the URL Data is not displayed in the URL
Servlet Code To Download the JAR
package com.download.jar;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet("/DownloadJarServlet")
public class DownloadJar extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
// 1. Helping the browser to understand that it is
// a jar file not an html content.
// Inorder to pass this information in response
// we set the content type as "application/jar"
// by calling setContentType() method in response object
response.setContentType("application/jar");
// 2. Getting the ServletContext object by calling
// getServletContext() method from the current servlet object
ServletContext ctx = getServletContext();
// 3. From ServletContext object we are calling getResourceAsStream()
// which returns the resource located at the named path as an InputStream object.
// The data in the InputStream can be of any type or length.
// This method returns null if no resource exists at the specified path.
// here we are passing the jar name present in the server at the relative path
InputStream is = ctx.getResourceAsStream("/mail.jar");
int read = 0;
byte[] noOfBytes = new byte[1024];
// 4. Getting the outputstream from the response object to write
// contents of jar to browser
OutputStream os = response.getOutputStream();
// 5. Reading the contents of jar in bytes using the inputstream created above
// and writing it to the browser through outputstream created above.
while((read = is.read(noOfBytes)) != -1 ){
os.write(noOfBytes, 0 , read);
}
os.flush();
os.close();
}
}
Dispatching Vs. Redirecting
When a servlet does a redirect, it’s like asking the client to call someone else instead. In this case, the client is
the browser, not the user. The browser makes the new call on the user’s behalf, after the originally-requested
servlet says, “Sorry, call this guy instead...”
The user sees the new URL in the browser.
When a servlet does a request dispatch, it’s like asking a co-worker to take over working with a client.
The co-worker ends up responding to the client, but the client doesn’t care as long as someone responds.
The user never knows someone else took over, because the URL in the browser bar doesn’t change.
THANKS!
Dr Pankaj Gupta
Head – ACCESS Health Digital
digital.health@accessh.org
Twitter: @pankajguptadr, @accesshdigital
LinkedIn: drpankajgupta, accesshdigital

More Related Content

What's hot

A CMD Core Model for CLARIN Web Services
A CMD Core Model for CLARIN Web ServicesA CMD Core Model for CLARIN Web Services
A CMD Core Model for CLARIN Web Services
Menzo Windhouwer
 
Session 26 - Servlets Part 2
Session 26 - Servlets Part 2Session 26 - Servlets Part 2
Session 26 - Servlets Part 2
PawanMM
 
jsf2 Notes
jsf2 Notesjsf2 Notes
jsf2 Notes
Rajiv Gupta
 
JSP - Part 1
JSP - Part 1JSP - Part 1
JSP - Part 1
Hitesh-Java
 
Jdbc architecture and driver types ppt
Jdbc architecture and driver types pptJdbc architecture and driver types ppt
Jdbc architecture and driver types ppt
kamal kotecha
 
Session 39 - Hibernate - Part 1
Session 39 - Hibernate - Part 1Session 39 - Hibernate - Part 1
Session 39 - Hibernate - Part 1
PawanMM
 
Basic Java Database Connectivity(JDBC)
Basic Java Database Connectivity(JDBC)Basic Java Database Connectivity(JDBC)
Basic Java Database Connectivity(JDBC)
suraj pandey
 
Angular jS Introduction by Google
Angular jS Introduction by GoogleAngular jS Introduction by Google
Angular jS Introduction by Google
ASG
 
Session 35 - Design Patterns
Session 35 - Design PatternsSession 35 - Design Patterns
Session 35 - Design Patterns
PawanMM
 
Xml Publisher And Reporting To Excel
Xml Publisher And Reporting To ExcelXml Publisher And Reporting To Excel
Xml Publisher And Reporting To Excel
Duncan Davies
 
Session 40 - Hibernate - Part 2
Session 40 - Hibernate - Part 2Session 40 - Hibernate - Part 2
Session 40 - Hibernate - Part 2
PawanMM
 
Session 25 - Introduction to JEE, Servlets
Session 25 - Introduction to JEE, ServletsSession 25 - Introduction to JEE, Servlets
Session 25 - Introduction to JEE, Servlets
PawanMM
 
Lecture 1: Introduction to JEE
Lecture 1:  Introduction to JEELecture 1:  Introduction to JEE
Lecture 1: Introduction to JEE
Fahad Golra
 
Session 34 - JDBC Best Practices, Introduction to Design Patterns
Session 34 - JDBC Best Practices, Introduction to Design PatternsSession 34 - JDBC Best Practices, Introduction to Design Patterns
Session 34 - JDBC Best Practices, Introduction to Design Patterns
PawanMM
 
Unit 1st and 3rd notes of java
Unit 1st and 3rd notes of javaUnit 1st and 3rd notes of java
Unit 1st and 3rd notes of java
Niraj Bharambe
 
WEB TECHNOLOGIES JSP
WEB TECHNOLOGIES  JSPWEB TECHNOLOGIES  JSP
Jdbc drivers
Jdbc driversJdbc drivers
Jdbc drivers
Prabhat gangwar
 
JDBC Connectivity Model
JDBC Connectivity ModelJDBC Connectivity Model
JDBC Connectivity Model
kunj desai
 
EJB 3.0 Java Persistence with Oracle TopLink
EJB 3.0 Java Persistence with Oracle TopLinkEJB 3.0 Java Persistence with Oracle TopLink
EJB 3.0 Java Persistence with Oracle TopLink
Bill Lyons
 

What's hot (19)

A CMD Core Model for CLARIN Web Services
A CMD Core Model for CLARIN Web ServicesA CMD Core Model for CLARIN Web Services
A CMD Core Model for CLARIN Web Services
 
Session 26 - Servlets Part 2
Session 26 - Servlets Part 2Session 26 - Servlets Part 2
Session 26 - Servlets Part 2
 
jsf2 Notes
jsf2 Notesjsf2 Notes
jsf2 Notes
 
JSP - Part 1
JSP - Part 1JSP - Part 1
JSP - Part 1
 
Jdbc architecture and driver types ppt
Jdbc architecture and driver types pptJdbc architecture and driver types ppt
Jdbc architecture and driver types ppt
 
Session 39 - Hibernate - Part 1
Session 39 - Hibernate - Part 1Session 39 - Hibernate - Part 1
Session 39 - Hibernate - Part 1
 
Basic Java Database Connectivity(JDBC)
Basic Java Database Connectivity(JDBC)Basic Java Database Connectivity(JDBC)
Basic Java Database Connectivity(JDBC)
 
Angular jS Introduction by Google
Angular jS Introduction by GoogleAngular jS Introduction by Google
Angular jS Introduction by Google
 
Session 35 - Design Patterns
Session 35 - Design PatternsSession 35 - Design Patterns
Session 35 - Design Patterns
 
Xml Publisher And Reporting To Excel
Xml Publisher And Reporting To ExcelXml Publisher And Reporting To Excel
Xml Publisher And Reporting To Excel
 
Session 40 - Hibernate - Part 2
Session 40 - Hibernate - Part 2Session 40 - Hibernate - Part 2
Session 40 - Hibernate - Part 2
 
Session 25 - Introduction to JEE, Servlets
Session 25 - Introduction to JEE, ServletsSession 25 - Introduction to JEE, Servlets
Session 25 - Introduction to JEE, Servlets
 
Lecture 1: Introduction to JEE
Lecture 1:  Introduction to JEELecture 1:  Introduction to JEE
Lecture 1: Introduction to JEE
 
Session 34 - JDBC Best Practices, Introduction to Design Patterns
Session 34 - JDBC Best Practices, Introduction to Design PatternsSession 34 - JDBC Best Practices, Introduction to Design Patterns
Session 34 - JDBC Best Practices, Introduction to Design Patterns
 
Unit 1st and 3rd notes of java
Unit 1st and 3rd notes of javaUnit 1st and 3rd notes of java
Unit 1st and 3rd notes of java
 
WEB TECHNOLOGIES JSP
WEB TECHNOLOGIES  JSPWEB TECHNOLOGIES  JSP
WEB TECHNOLOGIES JSP
 
Jdbc drivers
Jdbc driversJdbc drivers
Jdbc drivers
 
JDBC Connectivity Model
JDBC Connectivity ModelJDBC Connectivity Model
JDBC Connectivity Model
 
EJB 3.0 Java Persistence with Oracle TopLink
EJB 3.0 Java Persistence with Oracle TopLinkEJB 3.0 Java Persistence with Oracle TopLink
EJB 3.0 Java Persistence with Oracle TopLink
 

Similar to Java part 3

Ppt for Online music store
Ppt for Online music storePpt for Online music store
Ppt for Online music store
ADEEBANADEEM
 
Intorduction to struts
Intorduction to strutsIntorduction to struts
Intorduction to struts
Anup72
 
Servlet classnotes
Servlet classnotesServlet classnotes
Servlet classnotes
Vasanti Dutta
 
Lecture 19 - Dynamic Web - JAVA - Part 1.ppt
Lecture 19 - Dynamic Web - JAVA - Part 1.pptLecture 19 - Dynamic Web - JAVA - Part 1.ppt
Lecture 19 - Dynamic Web - JAVA - Part 1.ppt
KalsoomTahir2
 
Lecture 19 dynamic web - java - part 1
Lecture 19   dynamic web - java - part 1Lecture 19   dynamic web - java - part 1
Lecture 19 dynamic web - java - part 1Д. Ганаа
 
Web container and Apache Tomcat
Web container and Apache TomcatWeb container and Apache Tomcat
Web container and Apache Tomcat
Auwal Amshi
 
192563547-Servletsjhb,mnjhjhjm,nm,-Pres-ppt.ppt
192563547-Servletsjhb,mnjhjhjm,nm,-Pres-ppt.ppt192563547-Servletsjhb,mnjhjhjm,nm,-Pres-ppt.ppt
192563547-Servletsjhb,mnjhjhjm,nm,-Pres-ppt.ppt
sindhu991994
 
Advance Java Topics (J2EE)
Advance Java Topics (J2EE)Advance Java Topics (J2EE)
Advance Java Topics (J2EE)
slire
 
Anintroductiontojavawebtechnology 090324184240-phpapp01
Anintroductiontojavawebtechnology 090324184240-phpapp01Anintroductiontojavawebtechnology 090324184240-phpapp01
Anintroductiontojavawebtechnology 090324184240-phpapp01
raviIITRoorkee
 
Spatial approximate string search Doc
Spatial approximate string search DocSpatial approximate string search Doc
Spatial approximate string search Doc
Sudha Hari Tech Solution Pvt ltd
 
Ajp notes-chapter-06
Ajp notes-chapter-06Ajp notes-chapter-06
Ajp notes-chapter-06
Ankit Dubey
 
JEE Course - The Web Tier
JEE Course - The Web TierJEE Course - The Web Tier
JEE Course - The Web Tier
odedns
 
Servlets
ServletsServlets
Servlets
ZainabNoorGul
 
java Servlet technology
java Servlet technologyjava Servlet technology
java Servlet technology
Tanmoy Barman
 
JavaEE6 my way
JavaEE6 my wayJavaEE6 my way
JavaEE6 my way
Nicola Pedot
 
presentation on online movie ticket booking
presentation on online movie ticket bookingpresentation on online movie ticket booking
presentation on online movie ticket booking
dharmawath
 
Overview of JEE Technology
Overview of JEE TechnologyOverview of JEE Technology
Overview of JEE Technology
People Strategists
 
Java EE 7 introduction
Java EE 7  introductionJava EE 7  introduction
Java EE 7 introduction
Moumie Soulemane
 
Web Tech Java Servlet Update1
Web Tech   Java Servlet Update1Web Tech   Java Servlet Update1
Web Tech Java Servlet Update1vikram singh
 

Similar to Java part 3 (20)

Ppt for Online music store
Ppt for Online music storePpt for Online music store
Ppt for Online music store
 
Servlet by Rj
Servlet by RjServlet by Rj
Servlet by Rj
 
Intorduction to struts
Intorduction to strutsIntorduction to struts
Intorduction to struts
 
Servlet classnotes
Servlet classnotesServlet classnotes
Servlet classnotes
 
Lecture 19 - Dynamic Web - JAVA - Part 1.ppt
Lecture 19 - Dynamic Web - JAVA - Part 1.pptLecture 19 - Dynamic Web - JAVA - Part 1.ppt
Lecture 19 - Dynamic Web - JAVA - Part 1.ppt
 
Lecture 19 dynamic web - java - part 1
Lecture 19   dynamic web - java - part 1Lecture 19   dynamic web - java - part 1
Lecture 19 dynamic web - java - part 1
 
Web container and Apache Tomcat
Web container and Apache TomcatWeb container and Apache Tomcat
Web container and Apache Tomcat
 
192563547-Servletsjhb,mnjhjhjm,nm,-Pres-ppt.ppt
192563547-Servletsjhb,mnjhjhjm,nm,-Pres-ppt.ppt192563547-Servletsjhb,mnjhjhjm,nm,-Pres-ppt.ppt
192563547-Servletsjhb,mnjhjhjm,nm,-Pres-ppt.ppt
 
Advance Java Topics (J2EE)
Advance Java Topics (J2EE)Advance Java Topics (J2EE)
Advance Java Topics (J2EE)
 
Anintroductiontojavawebtechnology 090324184240-phpapp01
Anintroductiontojavawebtechnology 090324184240-phpapp01Anintroductiontojavawebtechnology 090324184240-phpapp01
Anintroductiontojavawebtechnology 090324184240-phpapp01
 
Spatial approximate string search Doc
Spatial approximate string search DocSpatial approximate string search Doc
Spatial approximate string search Doc
 
Ajp notes-chapter-06
Ajp notes-chapter-06Ajp notes-chapter-06
Ajp notes-chapter-06
 
JEE Course - The Web Tier
JEE Course - The Web TierJEE Course - The Web Tier
JEE Course - The Web Tier
 
Servlets
ServletsServlets
Servlets
 
java Servlet technology
java Servlet technologyjava Servlet technology
java Servlet technology
 
JavaEE6 my way
JavaEE6 my wayJavaEE6 my way
JavaEE6 my way
 
presentation on online movie ticket booking
presentation on online movie ticket bookingpresentation on online movie ticket booking
presentation on online movie ticket booking
 
Overview of JEE Technology
Overview of JEE TechnologyOverview of JEE Technology
Overview of JEE Technology
 
Java EE 7 introduction
Java EE 7  introductionJava EE 7  introduction
Java EE 7 introduction
 
Web Tech Java Servlet Update1
Web Tech   Java Servlet Update1Web Tech   Java Servlet Update1
Web Tech Java Servlet Update1
 

More from ACCESS Health Digital

Governance healthcare financial lever
Governance healthcare financial lever Governance healthcare financial lever
Governance healthcare financial lever
ACCESS Health Digital
 
Startup bootcamp 3
Startup bootcamp 3Startup bootcamp 3
Startup bootcamp 3
ACCESS Health Digital
 
Startup bootcamp 2
Startup bootcamp 2Startup bootcamp 2
Startup bootcamp 2
ACCESS Health Digital
 
Oops concepts
Oops conceptsOops concepts
Oops concepts
ACCESS Health Digital
 
Microservices
MicroservicesMicroservices
Microservices
ACCESS Health Digital
 
Hl7 & FHIR
Hl7 & FHIRHl7 & FHIR
Federated architecture
Federated architectureFederated architecture
Federated architecture
ACCESS Health Digital
 
E objects implementation
E objects implementationE objects implementation
E objects implementation
ACCESS Health Digital
 
Design patterns
Design patternsDesign patterns
Design patterns
ACCESS Health Digital
 
Database concepts
Database conceptsDatabase concepts
Database concepts
ACCESS Health Digital
 
Computer networks
Computer networksComputer networks
Computer networks
ACCESS Health Digital
 
Cloud computing
Cloud computingCloud computing
Cloud computing
ACCESS Health Digital
 
MDDS & NDHB Principles
MDDS & NDHB PrinciplesMDDS & NDHB Principles
MDDS & NDHB Principles
ACCESS Health Digital
 
Health information exchange (HIE)
Health information exchange (HIE)Health information exchange (HIE)
Health information exchange (HIE)
ACCESS Health Digital
 
Health insurance information platform (hiip)
Health insurance information platform (hiip)Health insurance information platform (hiip)
Health insurance information platform (hiip)
ACCESS Health Digital
 
Closed loop medication administration
Closed loop medication administrationClosed loop medication administration
Closed loop medication administration
ACCESS Health Digital
 
Health delivery information system [HDIS] MVP
Health delivery information system [HDIS] MVPHealth delivery information system [HDIS] MVP
Health delivery information system [HDIS] MVP
ACCESS Health Digital
 
HCIT is different
HCIT is differentHCIT is different
HCIT is different
ACCESS Health Digital
 

More from ACCESS Health Digital (20)

Governance healthcare financial lever
Governance healthcare financial lever Governance healthcare financial lever
Governance healthcare financial lever
 
Startup bootcamp 3
Startup bootcamp 3Startup bootcamp 3
Startup bootcamp 3
 
Startup bootcamp 2
Startup bootcamp 2Startup bootcamp 2
Startup bootcamp 2
 
Oops concepts
Oops conceptsOops concepts
Oops concepts
 
Microservices
MicroservicesMicroservices
Microservices
 
Java part 2
Java part  2Java part  2
Java part 2
 
Java part 1
Java part 1Java part 1
Java part 1
 
Hl7 & FHIR
Hl7 & FHIRHl7 & FHIR
Hl7 & FHIR
 
Federated architecture
Federated architectureFederated architecture
Federated architecture
 
E objects implementation
E objects implementationE objects implementation
E objects implementation
 
Design patterns
Design patternsDesign patterns
Design patterns
 
Database concepts
Database conceptsDatabase concepts
Database concepts
 
Computer networks
Computer networksComputer networks
Computer networks
 
Cloud computing
Cloud computingCloud computing
Cloud computing
 
MDDS & NDHB Principles
MDDS & NDHB PrinciplesMDDS & NDHB Principles
MDDS & NDHB Principles
 
Health information exchange (HIE)
Health information exchange (HIE)Health information exchange (HIE)
Health information exchange (HIE)
 
Health insurance information platform (hiip)
Health insurance information platform (hiip)Health insurance information platform (hiip)
Health insurance information platform (hiip)
 
Closed loop medication administration
Closed loop medication administrationClosed loop medication administration
Closed loop medication administration
 
Health delivery information system [HDIS] MVP
Health delivery information system [HDIS] MVPHealth delivery information system [HDIS] MVP
Health delivery information system [HDIS] MVP
 
HCIT is different
HCIT is differentHCIT is different
HCIT is different
 

Recently uploaded

AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
Product School
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
DianaGray10
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
Elena Simperl
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
Paul Groth
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Product School
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 

Recently uploaded (20)

AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMsTo Graph or Not to Graph Knowledge Graph Architectures and LLMs
To Graph or Not to Graph Knowledge Graph Architectures and LLMs
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 

Java part 3

  • 2. Java Enterprise Edition The Java EE is complete platform for developing multi-tiered distributed applications. It consists of: • The Java Virtual Machine (JVM). • The Java SE APIs (SE APIs). • The Java EE Application Server. • The Java EE APIs (EE APIs).  Specifications of standard API  Defined by the Java Community Process (JCP)  Java Specification Requests (JSRs): proposed and final specifications  Different implementation of same API  Example: JPA is implemented by Eclipselink, OpenJPA, Hibernate  Certifications  Architecture pattern  Large scale  Multi-tiers (Presentation Logic, Business Logic, Persistence)  Scalable  Reliable  Secure
  • 3. Java EE architecture Client Database EJB Container Web Container Application Client Application Client Web Browser Web Browser Enterprise Bean Servlet JSP Page Java EE Server Enterprise Bean Enterprise Bean JSP Page Servlet
  • 4. EJB – Enterprise Java Beans 1. What is a bean? • Beans are business logic components that implement a standard interface through which the bean is hooked into the bean container (= runtime object for bean). • A Java class implementing one of the standard bean interfaces is a bean. • Beans can be accessed remotely, usually from a client tier. Bean Bean container
  • 5. EJB Why EJB? Common concerns in different applications lead to re-implementing the same functionality for business logic components. Examples of common functionality: - Persistence - Transactions - Security - Runtime and lifecycle management (create, start, stop and delete component) EJB is a framework that provides the following services to applications: - Persistence - Transaction processing - Concurrency control (each client accesses its own bean instance) - Events using JMS (Java Messaging Service) - Naming and directory services via JNDI (Java Naming and Directory Interface) - Security using JAAS (Java Authentication and Authorization Service) - Deployment of software components to a server host - Remote procedure calls via RMI (RMI over IIOP) - Exposing business functionality via web services Business logic Front end (protocol, GUI) Backend (DB)
  • 6. Servlet  Java Servlet is a java object file developed as a component and runs on the server.  Servlets are programs that run on a Web or application server and act as a middle layer between a request coming from a Web browser or other HTTP client and databases or applications on the HTTP server Servlets is a component can be invoked from HTML. Note:  Servlets cannot run independently as a main application like the java applet, the servlet does not have main method.
  • 7.  Servlet do not display a graphical interface to the user.  A servlet’s work is done at the server and only the results of the servlet’s processing are returned to the client in the form of HTML.  A Servlet is a Java technology-based Web component, managed by a container that generates dynamic content.  Like other Java technology-based components, Servlets are platform-independent Java classes that are compiled to platform-neutral byte code that can be loaded dynamically into and run by a Java technology-enabled Web server. Servlet
  • 8. Advantages of Servlet  Platform Independence: Servlets are written entirely in java so these are platform independent. Servlets can run on any Servlet enabled web server.  Performance Due to interpreted nature of java, programs written in java are slow. But the java Servlets runs very fast. These are due to the way Servlets run on web server. For any program initialization takes significant amount of time. But in case of Servlets initialization takes place first time it receives a request and remains in memory till times out or server shut downs.
  • 9.  Extensibility Java Servlets are developed in java which is robust, well- designed and object oriented language which can be extended or polymorphed into new objects. So the java Servlets take all these advantages and can be extended from existing class to provide the ideal solutions.  4. Safety Java provides very good safety features like memory management, exception handling etc. Servlets inherits all these features and emerged as a very powerful web server extension.  5. Secure Servlets are server side components, so it inherits the security provided by the web server. Servlets are also benefited with Java Security Manager.
  • 10. JSP  JSP is one of the most powerful, easy-to-use, and fundamental tools in a Web-site developer's toolbox.  JSP combines HTML and XML with Java servlet (server application extension) and JavaBeans technologies to create a highly productive environment for developing and deploying reliable, interactive, high-performance platform- independent Web sites.  JSP facilitates the creation of dynamic content on the server.
  • 11.  It is part of the Java platform's integrated solution for server-side programming, which provides a portable alternative to other server- side technologies, such as CGI.  JSP integrates numerous Java application technologies, such as Java servlet, JavaBeans, JDBC, and Enterprise JavaBeans.  It also separates information presentation from application logic and fosters a reusable component model of programming.
  • 12. Advantages of JSP  Servlet use println statements for printing an HTML document which is usually very difficult to use. JSP has no such tedious task to maintain.  JSP needs no compilation, CLASSPATH setting and packaging.  In a JSP page visual content and logic are seperated, which is not possible in a servlet.  There is automatic deployment of a JSP; recompilation is done automatically when changes are made to JSP pages.  Usually with JSP, Java Beans and custom tags web application is simplified.
  • 13. Fundamental JSP Tags  JSP tags are an important syntax element of Java Server Pages which start with "<%" and end with "%>" just like HTML tags. JSP tags normally have a "start tag", a "tag body" and an "end tag". JSP tags can either be predefined tags or loaded from an external tag library.  Fundamental tags used in Java Server Pages are classified into the following categories:-  Declaration tag  Expression tag  Directive tag  Scriptlet tag  Comments
  • 14. HTTP- Hyper Text Transfer Protocol • Protocol: A Protocol is a standard procedure for defining and regulating communication. For example TCP,UDP, HTTP etc. • HTTP is the foundation of data communication for the World Wide Web. • The HTTP is the Web’s application-layer protocol for transferring various forms of data between server and client like plaintext, hypertext, image, videos and sounds .
  • 15. How HTTP Works? • The Hypertext Transfer Protocol (HTTP) is designed to enable communications between clients and servers. • HTTP works as a request-response protocol between a client and server. • Example: A client (browser) sends an HTTP request to the server; then the server returns a response to the client. The response contains status information about the request and may also contain the requested content. HTTP Methods •GET •POST •PUT •HEAD •DELETE •PATCH •OPTIONS The two most common HTTP methods are: GET and POST.
  • 16. How HTTP Works? Suppose client wants to visit www.yahoo.com
  • 17. How HTTP Works? (CONT.)
  • 18. How HTTP Works? (CONT.)
  • 19. How HTTP Works? (CONT.)
  • 20. How HTTP Works? (CONT.)
  • 21. Http Get Request GET is used to request data from a specified resource. GET is one of the most common HTTP methods. Note that the query string (name/value pairs) is sent in the URL of a GET request: /test/demo_form.php?name1=value1&name2=value2 Some other notes on GET requests: •GET requests can be cached •GET requests remain in the browser history •GET requests can be bookmarked •GET requests should never be used when dealing with sensitive data •GET requests have length restrictions •GET requests are only used to request data (not modify)
  • 22. Http Post Request The POST Method POST is used to send data to a server to create/update a resource. The data sent to the server with POST is stored in the request body of the HTTP request: POST /test/demo_form.php HTTP/1.1 Host: w3schools.com name1=value1&name2=value2 POST is one of the most common HTTP methods. Some other notes on POST requests: •POST requests are never cached •POST requests do not remain in the browser history •POST requests cannot be bookmarked •POST requests have no restrictions on data length
  • 23. HTML- Hyper Text Markup Language What is HTML? • HTML is a language for describing web pages. • HTML is not a programming language, it is a markup language • A markup language is a set of markup tags • HTML uses markup tags to describe web pages HTML Tags • HTML markup tags are usually called HTML tags • HTML tags are keywords surrounded by angle brackets like <html> • HTML tags normally come in pairs like <b> and </b> • The first tag in a pair is the start tag, the second tag is the end tag • Start and end tags are also called opening tags and closing tags .
  • 24. URL  URL stands for Uniform Resource Locator is the global address of documents and other resources on the World Wide Web. Its main purpose is to identify the location of a document and other resources available on the internet, and specify the mechanism for accessing it through a web browser.  A URL (Uniform Resource Locator) is a unique identifier used to locate a resource on the internet. It is also referred to as a web address.  URLs consist of multiple parts including a protocol and domain name that tell a web browser how and where to retrieve a resource  The URL contains the name of the protocol needed to access a resource, as well as a resource name
  • 25. Containers The application server provides the runtime platform in the form of containers. A container is a component of the application server that manages a specific type of components and provide them with all the needed services and Java EE API implementation. The two types of containers are: -Business Container The business container is responsible for managing business components and providing them with runtime services like: RMI communication, database manipulation, transaction services, etc. -Web Container The web container is responsible for managing web components and providing them with runtime services like: HTTP communication, database manipulation, etc.
  • 26. Servlet Life Cycle & Life Cycles Methods • Init () Method • Service () Method • Destroy() method Init () Method:-  During initialization stage of the Servlet life cycle, the web container initializes the servlet instance by calling the init() method.  The container passes an object implementing the ServletConfig interface via the init() method.  This configuration object allows the servlet to access name- value initialization parameters from the web application.
  • 27. • Service () Method:- ◦ After initialization, the servlet can service client requests. each request is serviced in its own separate thread. ◦ The Web container calls the service() method of the servlet for every request. ◦ The service() method determines the kind of request being made and dispatches it to an appropriate method to handle the request. ◦ The developer of the servlet must provide an implementation for these methods. If a request for a method that is not implemented by the servlet is made, the method of the parent class is called, typically resulting in an error being returned to the requester. • Destroy() method:- ◦ Finally, the Web container calls the destroy() method that takes the servlet out of service. The destroy() method, like init(), is called only once in the lifecycle of a servlet.
  • 28.
  • 31. Difference Between Get And Post GET POST BACK button/Reload Harmless Data will be re-submitted (the browser should alert the user that the data are about to be re-submitted) Bookmarked Can be bookmarked Cannot be bookmarked Cached Can be cached Not cached Encoding type application/x-www-form-urlencoded application/x-www-form-urlencoded or multipart/form-data. Use multipart encoding for binary data History Parameters remain in browser history Parameters are not saved in browser history Restrictions on data length Yes, when sending data, the GET method adds the data to the URL; and the length of a URL is limited (maximum URL length is 2048 characters) No restrictions Restrictions on data type Only ASCII characters allowed No restrictions. Binary data is also allowed Security GET is less secure compared to POST because data sent is part of the URL Never use GET when sending passwords or other sensitive information! POST is a little safer than GET because the parameters are not stored in browser history or in web server logs Visibility Data is visible to everyone in the URL Data is not displayed in the URL
  • 32. Servlet Code To Download the JAR package com.download.jar; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import javax.servlet.ServletContext; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @WebServlet("/DownloadJarServlet") public class DownloadJar extends HttpServlet { private static final long serialVersionUID = 1L; protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // 1. Helping the browser to understand that it is // a jar file not an html content. // Inorder to pass this information in response // we set the content type as "application/jar" // by calling setContentType() method in response object response.setContentType("application/jar"); // 2. Getting the ServletContext object by calling // getServletContext() method from the current servlet object ServletContext ctx = getServletContext(); // 3. From ServletContext object we are calling getResourceAsStream() // which returns the resource located at the named path as an InputStream object. // The data in the InputStream can be of any type or length. // This method returns null if no resource exists at the specified path. // here we are passing the jar name present in the server at the relative path InputStream is = ctx.getResourceAsStream("/mail.jar"); int read = 0; byte[] noOfBytes = new byte[1024]; // 4. Getting the outputstream from the response object to write // contents of jar to browser OutputStream os = response.getOutputStream(); // 5. Reading the contents of jar in bytes using the inputstream created above // and writing it to the browser through outputstream created above. while((read = is.read(noOfBytes)) != -1 ){ os.write(noOfBytes, 0 , read); } os.flush(); os.close(); } }
  • 33. Dispatching Vs. Redirecting When a servlet does a redirect, it’s like asking the client to call someone else instead. In this case, the client is the browser, not the user. The browser makes the new call on the user’s behalf, after the originally-requested servlet says, “Sorry, call this guy instead...” The user sees the new URL in the browser. When a servlet does a request dispatch, it’s like asking a co-worker to take over working with a client. The co-worker ends up responding to the client, but the client doesn’t care as long as someone responds. The user never knows someone else took over, because the URL in the browser bar doesn’t change.
  • 34. THANKS! Dr Pankaj Gupta Head – ACCESS Health Digital digital.health@accessh.org Twitter: @pankajguptadr, @accesshdigital LinkedIn: drpankajgupta, accesshdigital