Java part 3

ACCESS Health Digital
ACCESS Health DigitalDigital Health Research um ACCESS Health Digital
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.
Java part  3
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
1 von 34

Recomendados

Java Web Programming [1/9] : Introduction to Web Application von
Java Web Programming [1/9] : Introduction to Web ApplicationJava Web Programming [1/9] : Introduction to Web Application
Java Web Programming [1/9] : Introduction to Web ApplicationIMC Institute
4.7K views53 Folien
Java ee introduction von
Java ee introductionJava ee introduction
Java ee introductionMoumie Soulemane
483 views21 Folien
1. Spring intro IoC von
1. Spring intro IoC1. Spring intro IoC
1. Spring intro IoCASG
29 views12 Folien
Session 37 - JSP - Part 2 (final) von
Session 37 - JSP - Part 2 (final)Session 37 - JSP - Part 2 (final)
Session 37 - JSP - Part 2 (final)PawanMM
69 views28 Folien
Unit 4 web technology uptu von
Unit 4 web technology uptuUnit 4 web technology uptu
Unit 4 web technology uptuAbhishek Kesharwani
1.6K views22 Folien
Session 36 - JSP - Part 1 von
Session 36 - JSP - Part 1Session 36 - JSP - Part 1
Session 36 - JSP - Part 1PawanMM
67 views30 Folien

Más contenido relacionado

Was ist angesagt?

A CMD Core Model for CLARIN Web Services von
A CMD Core Model for CLARIN Web ServicesA CMD Core Model for CLARIN Web Services
A CMD Core Model for CLARIN Web ServicesMenzo Windhouwer
713 views23 Folien
Session 26 - Servlets Part 2 von
Session 26 - Servlets Part 2Session 26 - Servlets Part 2
Session 26 - Servlets Part 2PawanMM
64 views31 Folien
jsf2 Notes von
jsf2 Notesjsf2 Notes
jsf2 NotesRajiv Gupta
1.2K views45 Folien
JSP - Part 1 von
JSP - Part 1JSP - Part 1
JSP - Part 1Hitesh-Java
188 views30 Folien
Jdbc architecture and driver types ppt von
Jdbc architecture and driver types pptJdbc architecture and driver types ppt
Jdbc architecture and driver types pptkamal kotecha
34.1K views32 Folien
Session 39 - Hibernate - Part 1 von
Session 39 - Hibernate - Part 1Session 39 - Hibernate - Part 1
Session 39 - Hibernate - Part 1PawanMM
56 views26 Folien

Was ist angesagt?(19)

A CMD Core Model for CLARIN Web Services von Menzo Windhouwer
A CMD Core Model for CLARIN Web ServicesA CMD Core Model for CLARIN Web Services
A CMD Core Model for CLARIN Web Services
Menzo Windhouwer713 views
Session 26 - Servlets Part 2 von PawanMM
Session 26 - Servlets Part 2Session 26 - Servlets Part 2
Session 26 - Servlets Part 2
PawanMM64 views
Jdbc architecture and driver types ppt von kamal kotecha
Jdbc architecture and driver types pptJdbc architecture and driver types ppt
Jdbc architecture and driver types ppt
kamal kotecha34.1K views
Session 39 - Hibernate - Part 1 von PawanMM
Session 39 - Hibernate - Part 1Session 39 - Hibernate - Part 1
Session 39 - Hibernate - Part 1
PawanMM56 views
Basic Java Database Connectivity(JDBC) von suraj pandey
Basic Java Database Connectivity(JDBC)Basic Java Database Connectivity(JDBC)
Basic Java Database Connectivity(JDBC)
suraj pandey566 views
Angular jS Introduction by Google von ASG
Angular jS Introduction by GoogleAngular jS Introduction by Google
Angular jS Introduction by Google
ASG99 views
Session 35 - Design Patterns von PawanMM
Session 35 - Design PatternsSession 35 - Design Patterns
Session 35 - Design Patterns
PawanMM46 views
Xml Publisher And Reporting To Excel von Duncan Davies
Xml Publisher And Reporting To ExcelXml Publisher And Reporting To Excel
Xml Publisher And Reporting To Excel
Duncan Davies14.4K views
Session 40 - Hibernate - Part 2 von PawanMM
Session 40 - Hibernate - Part 2Session 40 - Hibernate - Part 2
Session 40 - Hibernate - Part 2
PawanMM103 views
Session 25 - Introduction to JEE, Servlets von PawanMM
Session 25 - Introduction to JEE, ServletsSession 25 - Introduction to JEE, Servlets
Session 25 - Introduction to JEE, Servlets
PawanMM85 views
Lecture 1: Introduction to JEE von Fahad Golra
Lecture 1:  Introduction to JEELecture 1:  Introduction to JEE
Lecture 1: Introduction to JEE
Fahad Golra1.6K views
Session 34 - JDBC Best Practices, Introduction to Design Patterns von PawanMM
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
PawanMM66 views
Unit 1st and 3rd notes of java von Niraj Bharambe
Unit 1st and 3rd notes of javaUnit 1st and 3rd notes of java
Unit 1st and 3rd notes of java
Niraj Bharambe1.9K views
JDBC Connectivity Model von kunj desai
JDBC Connectivity ModelJDBC Connectivity Model
JDBC Connectivity Model
kunj desai2.3K views
EJB 3.0 Java Persistence with Oracle TopLink von Bill Lyons
EJB 3.0 Java Persistence with Oracle TopLinkEJB 3.0 Java Persistence with Oracle TopLink
EJB 3.0 Java Persistence with Oracle TopLink
Bill Lyons3.4K views

Similar a Java part 3

Ppt for Online music store von
Ppt for Online music storePpt for Online music store
Ppt for Online music storeADEEBANADEEM
3.7K views30 Folien
Intorduction to struts von
Intorduction to strutsIntorduction to struts
Intorduction to strutsAnup72
3.4K views64 Folien
Servlet classnotes von
Servlet classnotesServlet classnotes
Servlet classnotesVasanti Dutta
86 views46 Folien
Lecture 19 - Dynamic Web - JAVA - Part 1.ppt von
Lecture 19 - Dynamic Web - JAVA - Part 1.pptLecture 19 - Dynamic Web - JAVA - Part 1.ppt
Lecture 19 - Dynamic Web - JAVA - Part 1.pptKalsoomTahir2
3 views79 Folien
Lecture 19 dynamic web - java - part 1 von
Lecture 19   dynamic web - java - part 1Lecture 19   dynamic web - java - part 1
Lecture 19 dynamic web - java - part 1Д. Ганаа
1.6K views79 Folien

Similar a Java part 3(20)

Ppt for Online music store von ADEEBANADEEM
Ppt for Online music storePpt for Online music store
Ppt for Online music store
ADEEBANADEEM3.7K views
Intorduction to struts von Anup72
Intorduction to strutsIntorduction to struts
Intorduction to struts
Anup723.4K views
Lecture 19 - Dynamic Web - JAVA - Part 1.ppt von KalsoomTahir2
Lecture 19 - Dynamic Web - JAVA - Part 1.pptLecture 19 - Dynamic Web - JAVA - Part 1.ppt
Lecture 19 - Dynamic Web - JAVA - Part 1.ppt
KalsoomTahir23 views
Lecture 19 dynamic web - java - part 1 von Д. Ганаа
Lecture 19   dynamic web - java - part 1Lecture 19   dynamic web - java - part 1
Lecture 19 dynamic web - java - part 1
Д. Ганаа1.6K views
Web container and Apache Tomcat von Auwal Amshi
Web container and Apache TomcatWeb container and Apache Tomcat
Web container and Apache Tomcat
Auwal Amshi1.5K views
Advance Java Topics (J2EE) von slire
Advance Java Topics (J2EE)Advance Java Topics (J2EE)
Advance Java Topics (J2EE)
slire35.1K views
Anintroductiontojavawebtechnology 090324184240-phpapp01 von raviIITRoorkee
Anintroductiontojavawebtechnology 090324184240-phpapp01Anintroductiontojavawebtechnology 090324184240-phpapp01
Anintroductiontojavawebtechnology 090324184240-phpapp01
raviIITRoorkee246 views
JEE Course - The Web Tier von odedns
JEE Course - The Web TierJEE Course - The Web Tier
JEE Course - The Web Tier
odedns2.8K views
java Servlet technology von Tanmoy Barman
java Servlet technologyjava Servlet technology
java Servlet technology
Tanmoy Barman8.6K views
presentation on online movie ticket booking von dharmawath
presentation on online movie ticket bookingpresentation on online movie ticket booking
presentation on online movie ticket booking
dharmawath6.7K views
Web Tech Java Servlet Update1 von vikram singh
Web Tech   Java Servlet Update1Web Tech   Java Servlet Update1
Web Tech Java Servlet Update1
vikram singh1.8K views
Web programming and development - Introduction von Joel Briza
Web programming and development - IntroductionWeb programming and development - Introduction
Web programming and development - Introduction
Joel Briza1.7K views

Más de ACCESS Health Digital

Governance healthcare financial lever von
Governance healthcare financial lever Governance healthcare financial lever
Governance healthcare financial lever ACCESS Health Digital
87 views40 Folien
Startup bootcamp 3 von
Startup bootcamp 3Startup bootcamp 3
Startup bootcamp 3ACCESS Health Digital
58 views99 Folien
Startup bootcamp 2 von
Startup bootcamp 2Startup bootcamp 2
Startup bootcamp 2ACCESS Health Digital
50 views72 Folien
Oops concepts von
Oops conceptsOops concepts
Oops conceptsACCESS Health Digital
111 views17 Folien
Microservices von
MicroservicesMicroservices
MicroservicesACCESS Health Digital
181 views26 Folien
Java part 2 von
Java part  2Java part  2
Java part 2ACCESS Health Digital
14 views21 Folien

Más de ACCESS Health Digital(20)

Último

CloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlue von
CloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlueCloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlue
CloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlueShapeBlue
93 views15 Folien
DRaaS using Snapshot copy and destination selection (DRaaS) - Alexandre Matti... von
DRaaS using Snapshot copy and destination selection (DRaaS) - Alexandre Matti...DRaaS using Snapshot copy and destination selection (DRaaS) - Alexandre Matti...
DRaaS using Snapshot copy and destination selection (DRaaS) - Alexandre Matti...ShapeBlue
98 views29 Folien
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas... von
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...Bernd Ruecker
50 views69 Folien
Centralized Logging Feature in CloudStack using ELK and Grafana - Kiran Chava... von
Centralized Logging Feature in CloudStack using ELK and Grafana - Kiran Chava...Centralized Logging Feature in CloudStack using ELK and Grafana - Kiran Chava...
Centralized Logging Feature in CloudStack using ELK and Grafana - Kiran Chava...ShapeBlue
101 views17 Folien
Declarative Kubernetes Cluster Deployment with Cloudstack and Cluster API - O... von
Declarative Kubernetes Cluster Deployment with Cloudstack and Cluster API - O...Declarative Kubernetes Cluster Deployment with Cloudstack and Cluster API - O...
Declarative Kubernetes Cluster Deployment with Cloudstack and Cluster API - O...ShapeBlue
88 views13 Folien
Backroll, News and Demo - Pierre Charton, Matthias Dhellin, Ousmane Diarra - ... von
Backroll, News and Demo - Pierre Charton, Matthias Dhellin, Ousmane Diarra - ...Backroll, News and Demo - Pierre Charton, Matthias Dhellin, Ousmane Diarra - ...
Backroll, News and Demo - Pierre Charton, Matthias Dhellin, Ousmane Diarra - ...ShapeBlue
146 views15 Folien

Último(20)

CloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlue von ShapeBlue
CloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlueCloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlue
CloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlue
ShapeBlue93 views
DRaaS using Snapshot copy and destination selection (DRaaS) - Alexandre Matti... von ShapeBlue
DRaaS using Snapshot copy and destination selection (DRaaS) - Alexandre Matti...DRaaS using Snapshot copy and destination selection (DRaaS) - Alexandre Matti...
DRaaS using Snapshot copy and destination selection (DRaaS) - Alexandre Matti...
ShapeBlue98 views
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas... von Bernd Ruecker
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...
iSAQB Software Architecture Gathering 2023: How Process Orchestration Increas...
Bernd Ruecker50 views
Centralized Logging Feature in CloudStack using ELK and Grafana - Kiran Chava... von ShapeBlue
Centralized Logging Feature in CloudStack using ELK and Grafana - Kiran Chava...Centralized Logging Feature in CloudStack using ELK and Grafana - Kiran Chava...
Centralized Logging Feature in CloudStack using ELK and Grafana - Kiran Chava...
ShapeBlue101 views
Declarative Kubernetes Cluster Deployment with Cloudstack and Cluster API - O... von ShapeBlue
Declarative Kubernetes Cluster Deployment with Cloudstack and Cluster API - O...Declarative Kubernetes Cluster Deployment with Cloudstack and Cluster API - O...
Declarative Kubernetes Cluster Deployment with Cloudstack and Cluster API - O...
ShapeBlue88 views
Backroll, News and Demo - Pierre Charton, Matthias Dhellin, Ousmane Diarra - ... von ShapeBlue
Backroll, News and Demo - Pierre Charton, Matthias Dhellin, Ousmane Diarra - ...Backroll, News and Demo - Pierre Charton, Matthias Dhellin, Ousmane Diarra - ...
Backroll, News and Demo - Pierre Charton, Matthias Dhellin, Ousmane Diarra - ...
ShapeBlue146 views
Backup and Disaster Recovery with CloudStack and StorPool - Workshop - Venko ... von ShapeBlue
Backup and Disaster Recovery with CloudStack and StorPool - Workshop - Venko ...Backup and Disaster Recovery with CloudStack and StorPool - Workshop - Venko ...
Backup and Disaster Recovery with CloudStack and StorPool - Workshop - Venko ...
ShapeBlue144 views
Import Export Virtual Machine for KVM Hypervisor - Ayush Pandey - University ... von ShapeBlue
Import Export Virtual Machine for KVM Hypervisor - Ayush Pandey - University ...Import Export Virtual Machine for KVM Hypervisor - Ayush Pandey - University ...
Import Export Virtual Machine for KVM Hypervisor - Ayush Pandey - University ...
ShapeBlue79 views
CloudStack and GitOps at Enterprise Scale - Alex Dometrius, Rene Glover - AT&T von ShapeBlue
CloudStack and GitOps at Enterprise Scale - Alex Dometrius, Rene Glover - AT&TCloudStack and GitOps at Enterprise Scale - Alex Dometrius, Rene Glover - AT&T
CloudStack and GitOps at Enterprise Scale - Alex Dometrius, Rene Glover - AT&T
ShapeBlue112 views
Extending KVM Host HA for Non-NFS Storage - Alex Ivanov - StorPool von ShapeBlue
Extending KVM Host HA for Non-NFS Storage -  Alex Ivanov - StorPoolExtending KVM Host HA for Non-NFS Storage -  Alex Ivanov - StorPool
Extending KVM Host HA for Non-NFS Storage - Alex Ivanov - StorPool
ShapeBlue84 views
Zero to Cloud Hero: Crafting a Private Cloud from Scratch with XCP-ng, Xen Or... von ShapeBlue
Zero to Cloud Hero: Crafting a Private Cloud from Scratch with XCP-ng, Xen Or...Zero to Cloud Hero: Crafting a Private Cloud from Scratch with XCP-ng, Xen Or...
Zero to Cloud Hero: Crafting a Private Cloud from Scratch with XCP-ng, Xen Or...
ShapeBlue158 views
Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P... von ShapeBlue
Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P...Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P...
Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P...
ShapeBlue154 views
Updates on the LINSTOR Driver for CloudStack - Rene Peinthor - LINBIT von ShapeBlue
Updates on the LINSTOR Driver for CloudStack - Rene Peinthor - LINBITUpdates on the LINSTOR Driver for CloudStack - Rene Peinthor - LINBIT
Updates on the LINSTOR Driver for CloudStack - Rene Peinthor - LINBIT
ShapeBlue166 views
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLive von Network Automation Forum
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLiveAutomating a World-Class Technology Conference; Behind the Scenes of CiscoLive
Automating a World-Class Technology Conference; Behind the Scenes of CiscoLive
Why and How CloudStack at weSystems - Stephan Bienek - weSystems von ShapeBlue
Why and How CloudStack at weSystems - Stephan Bienek - weSystemsWhy and How CloudStack at weSystems - Stephan Bienek - weSystems
Why and How CloudStack at weSystems - Stephan Bienek - weSystems
ShapeBlue197 views
"Surviving highload with Node.js", Andrii Shumada von Fwdays
"Surviving highload with Node.js", Andrii Shumada "Surviving highload with Node.js", Andrii Shumada
"Surviving highload with Node.js", Andrii Shumada
Fwdays53 views
Hypervisor Agnostic DRS in CloudStack - Brief overview & demo - Vishesh Jinda... von ShapeBlue
Hypervisor Agnostic DRS in CloudStack - Brief overview & demo - Vishesh Jinda...Hypervisor Agnostic DRS in CloudStack - Brief overview & demo - Vishesh Jinda...
Hypervisor Agnostic DRS in CloudStack - Brief overview & demo - Vishesh Jinda...
ShapeBlue120 views
KVM Security Groups Under the Hood - Wido den Hollander - Your.Online von ShapeBlue
KVM Security Groups Under the Hood - Wido den Hollander - Your.OnlineKVM Security Groups Under the Hood - Wido den Hollander - Your.Online
KVM Security Groups Under the Hood - Wido den Hollander - Your.Online
ShapeBlue181 views

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.
  • 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