0% found this document useful (0 votes)
20 views

Ejava 11

The document discusses Java EE and its components, servlets and their lifecycle, JDBC and its types, session beans and their types, cookies, request dispatcher and its methods, JSP directives and implicit objects, and advantages of JSTL over JSP.

Uploaded by

rexos83460
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

Ejava 11

The document discusses Java EE and its components, servlets and their lifecycle, JDBC and its types, session beans and their types, cookies, request dispatcher and its methods, JSP directives and implicit objects, and advantages of JSTL over JSP.

Uploaded by

rexos83460
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Java ee and architecture Javax.servlet and javax.servlet.http Jsp ?

reason to use jsp


The Java EE provides a platform for developers with enterprise 1. The javax.servlet package contains many interfaces and classes JavaServer Pages (JSP) is a technology for developing Webpages
features such as distributed computing and web services. Java EE that are used by the servlet or web container. These are not that supports dynamic content. This helps developers insert java
applications are usually run on reference run times such as specific to any protocol. Interfaces in javax.servlet package are: code in HTML pages by making use of special JSP tags, most of
microservers or application servers. Examples of some contexts Servlet, ServletRequest, ServletResponse, RequestDispatcher . which start with <% and end with %>. A JavaServer Pages
where Java EE is used are e-commerce, accounting, banking Classes in javax.servlet package are: GenericServlet, component is a type of Java servlet that is designed to fulfill the
information systems. The component-based and platform ServletInputStream, ServletOutputStream, role of a user interface for a Java web application. Web developers
independent Java EE architecture makes Java EE applications easy ServletRequestWrapper. write JSPs as text files that combine HTML or XHTML code, XML
to write because business logic is organized into reusable 2. The javax.servlet.http package contains interfaces and classes elements, and embedded JSP actions and commands. Reasons to
components and the Java EE server provides underlying services that are responsible for http requests only. Interfaces in use jsp : 1. Nobody can borrow the code. 2.Fast loading of page.
in the form of a container for every component type. 1.Containers javax.servlet.http package are: HttpServletRequest, 3.No Browser compatibility issue. 4.Java support. 5. Compilation
and Services-Component are installed in their containers during HttpServletResponse, HttpSession. Classes in javax.servlet.http 6. JSP elements in XML or HTML page.
deployment and are the interface between a component and the package are: HttpServlet, Cookie, HttpServletRequestWrapper.
low-level platform-specific functionality that supports the Directives and attributes
component. 2. Container types- enterprise java bean (ejb) Request dispatcher and and its methods The jsp directives are messages that tells the web container how
container, web container, application client container, applet The RequestDispatcher is an Interface that comes under package to translate a JSP page into the corresponding servlet. There are
container. javax.servlet. Using this interface we get an object in servlet after three types of directives: page directive, include directive, taglib
receiving the request. Using the RequestDispatcher object we directive. The page directive defines attributes that apply to an
Servlet and life cycle send a request to other resources which include (servlet, HTML entire JSP page. Attributes of JSP page directive are : 1. Import-
Servlet is a technology which is used to create a web application. file, or JSP file). A RequestDispatcher object can be used to The import attribute is used to import class,interface or all the
Servlet is an API that provides many interfaces and classes forward a request to the resource or to include the resource in a members of a package. 2. contentType-The contentType attribute
including documentation. Servlet is an interface that must be response. The resource can be dynamic or static. Methods : 1. defines the MIME(Multipurpose Internet Mail Extension) type of
implemented for creating any Servlet. Servlet is a class that forward()-This method is used to forward a request from a the HTTP response. 3. Extends-The extends attribute defines the
extends the capabilities of the servers and responds to the servlet to another resource (servlet, JSP file, or HTML file) on the parent class that will be inherited by the generated servlet.It is
incoming requests. It can respond to any requests. Servlet is a server. 2. include()-This method is used to include the response rarely used. 4. Info-This attribute simply sets the information of
web component that is deployed on the server to create a of resource(for which the request passed servlet, JSP page, HTML the JSP page which is retrieved later by using getServletInfo()
dynamic web page. Life cycle- The web container maintains the file) in the current servlet response. method of Servlet interface.
life cycle of a servlet instance. Let's see the life cycle of the servlet:
1. Servlet class is loaded-The classloader is responsible to load Session and its types Jsp implicit objects
the servlet class. 2. Servlet instance is created-The web container Session bean encapsulates business logic only, it can be invoked Jsp Objects are the Java objects that the JSP Container makes
creates the instance of a servlet after loading the servlet class. 3. by local, remote and webservice client. It can be used for available to the developers in each page and the developer can
init method is invoked-The web container calls the init method calculations, database access etc. The life cycle of session bean is call them directly without being explicitly declared. JSP Implicit
only once after creating the servlet instance. 4. service method is maintained by the application server (EJB Container). Types : 1. Objects are also called pre-defined variables. There are 9 jsp
invoked-The web container calls the service method each time Stateless Session Bean-It doesn't maintain state of a client implicit objects : 1. request-This is the HttpServletRequest object
when request for the servlet is received. 5. destroy method is between multiple method calls. 2. Stateful Session Bean-It associated with the request. 2. response-This is the
invoked-The web container calls the destroy method before maintains state of a client across multiple requests. 3. Singleton HttpServletResponse object associated with the response to the
removing the servlet instance from the service. Session Bean-One instance per application, it is shared between client. 3. out-This is the PrintWriter object used to send output to
clients and supports concurrent access. the client. 4. session-This is the HttpSession object associated
Jdbc and its types with the request. 5.application . 6. config . 7. pageContext. 8. page.
JDBC or Java Database Connectivity is a Java API to connect and Cookies 9. Exception.
execute the query with the database. The classes and interfaces of A cookie is a small piece of information that is persisted between
JDBC allow the application to send requests made by users to the the multiple client requests. A cookie has a name, a single value, Advantage of jstl over jsp
specified database. It is used to write programs required to access and optional attributes such as a comment, path and domain 1. Standard Tag: It provides a rich layer of the portable
databases. JDBC, along with the database driver, can access qualifiers, a maximum age, and a version number. some functionality of JSP pages. It's easy for a developer to understand
databases and spreadsheets. Types of jdbc driver : 1. JDBC-ODBC commonly used methods of the Cookie class are : 1. public void the code. 2. Code Neat and Clean: As scriplets confuse developer,
bridge driver-The JDBC-ODBC bridge driver uses ODBC driver to setMaxAge(int expiry)- Sets the maximum age of the cookie in the usage of JSTL makes the code neat and clean. 3. Automatic
connect to the database. 2. Native-API driver-The Native API seconds. 2. public String getName()- Returns the name of the JavabeansInterospection Support: It has an advantage of JSTL
driver uses the client-side libraries of the database. 3. Network cookie. The name cannot be changed after creation. 3. public over JSP scriptlets. JSTL Expression language handles JavaBean
Protocol driver-The Network Protocol driver uses middleware String getValue()- Returns the value of the cookie. 4. public void code very easily. We don't need to downcast the objects, which
that converts JDBC calls directly or indirectly into the vendor- setName(String name)-changes the name of the cookie. has been retrieved as scoped attributes. Using JSP scriptlets code
specific database protocol. 4. Thin driver-The thin driver will be complicated, and JSTL has simplified that purpose. 4.
converts JDBC calls directly into the vendor-specific database Session tracking? Ways to track session Easier for humans to read: JSTL is based on XML, which is very
protocol. Session Tracking is a way to maintain state (data) of an user. It is similar to HTML. Hence, it is easy for the developers to
also known as session management in servlet. Http protocol is a understand. 5. Easier for computers to understand: Tools such as
Jdbc architecture stateless so we need to maintain state using session tracking Dreamweaver and front page are generating more and more
1.Application: It is a java applet or a servlet that communicates techniques. Each time user requests to the server, server treats HTML code. HTML tools do a great job of formatting HTML code.
with a data source. 2. The JDBC API: The JDBC API allows Java the request as the new request. So we need to maintain the state The HTML code is mixed with the scriplet code. As JSTL is
programs to execute SQL statements and retrieve results. Some of of an user to recognize to particular user. Techniques : 1. Cookies- expressed as XML compliant tags, it is easy for HTML generation
the important classes and interfaces defined in JDBC API are as Cookies are little pieces of data delivered by the web server in the to parse the JSTL code within the document.
follows: 3. DriverManager: It plays an important role in the JDBC response header and kept by the browser. 2. Hidden Form Field-
architecture. It uses some database-specific drivers to effectively The information is inserted into the web pages via the hidden
connect enterprise applications to databases. 4. JDBC drivers: To form field, which is then transferred to the server. 3. URL Enterprise java beans and benefits
communicate with a data source through JDBC, you need a JDBC Rewriting-With each request and return, append some more data Enterprise Java Beans (EJB) is one of the several Java APIs for
driver that intelligently communicates with the respective data via URL as request parameters. standard manufacture of enterprise software. EJB is a server-side
source. software element that summarizes business logic of an
Non blocking i/o and its working application. Enterprise Java Beans web repository yields a
Java container and types Non blocking IO does not wait for the data to be read or write runtime domain for web related software elements including
Containers are the interface between a component and the low- before returning. Java NIO non- blocking mode allows the thread computer reliability, Java Servlet Lifecycle (JSL) management,
level platform-specific functionality that supports the component. to request writing data to a channel, but not wait for it to be fully transaction procedure and other web services. Benefits : 1.
Before a web, enterprise bean, or application client component written. The thread is allowed to go on and do something else in a Completely focus of business logic. 2. Reusable components. 3.
can be executed, it must be assembled into a Java EE module and mean time. java NIO is buffer oriented I/O approach. Data is read Portable. 4.Fast building of Application. 5. One Business logic may
deployed into its container. Types : 1. Java EE server: The into a buffer from which it is further processed using a channel. In have multiple presentation logic.
runtime portion of a Java EE product. A Java EE server provides NIO we deal with the channel and buffer for I/O operation. The
EJB and web containers. 2. Enterprise JavaBeans (EJB) container: major difference between a channel and a stream is: 1. A stream Interceptor? Role of aroundinvoke method
Manages the execution of enterprise beans for Java EE can be used for one-way data transfer. 2.A channel provides a Interceptors are used in conjunction with Java EE managed
applications. 3. Web container: Manages the execution of JSP two-way data transfer facility. Channel : In Java NIO, the channel classes to allow developers to invoke interceptor methods on an
page and servlet components for Java EE applications. 4. is a medium that transports the data efficiently between the associated target class, in conjunction with method invocations or
Application client container: Manages the execution of application entity and byte buffers. Selectors : In Java NIO the selector is a lifecycle events. Common uses of interceptors are logging,
client components. 5. Applet container: Manages the execution of multiplexor of selectable channels, which is used as a special type auditing, and profiling. Aroundinvoke method : An AroundInvoke
applets. Consists of a web browser and Java Plug-in running on of channel that can be put into non-blocking mode. method can invoke any component or resource that the method it
the client together. is intercepting can invoke. AroundInvoke method invocations
El and types of expression in el occur within the same transaction and security context as the
JSP Expression Language (EL) makes it possible to easily access method on which they are interposing.
application data stored in JavaBeans components. JSP EL allows
you to create expressions both (a) arithmetic and (b) logical. Types of beans
Within a JSP EL expression, you can use integers, floating point 1. Session Bean-Session bean contains business logic that can be
numbers, strings, the built-in constants true and false for boolean invoked by local, remote or webservice client. 2. Message Driven
values, and null. Operatiors in el : 1. . 2. () 3. [] 4. + 5. - . El implicit Bean-Like Session Bean, it contains the business logic but it is
objects : 1. pageScope. 2. requestScope. 3. sessionScope. 4. invoked by passing message. 3. Entity Bean-It encapsulates the
applicationScope. state that can be persisted in the database. It is deprecated. Now,
it is replaced with JPA (Java Persistent API).
Life cycle of message driven beans
The EJB container usually creates a pool of message-driven bean
instances. For each instance, the EJB container performs these
tasks: 1. If the message-driven bean uses dependency injection,
the container injects these references before instantiating the
instance. 2. The container calls the method annotated
@PostConstruct, if any.
Like a stateless session bean, a message-driven bean is never
passivated, and it has only two states: nonexistent and ready to
receive messages.At the end of the life cycle, the container calls
the method annotated @PreDestroy, if any. The bean’s instance is
then ready for garbage collection.

Sesson beans and its types


A session bean encapsulates business logic that can be invoked
programmatically by a client over local, remote, or web service
client views. To access an application that is deployed on the
server, the client invokes the session bean’s methods. Types : 1.
Stateful Session Beans-In a stateful session bean, the instance
variables represent the state of a unique client/bean session.
Because the client interacts (“talks”) with its bean, this state is
often called the conversational state. 2. Stateless Session Beans-A
stateless session bean does not maintain a conversational state
with the client. 3. Singleton Session Beans-A singleton session
bean is instantiated once per application and exists for the
lifecycle of the application.

Enterprise bean container


EJB container is a server-side component that comprises the
business logic. It offers local and remote access to the enterprise
beans. In other words, we can say that it provides a runtime
environment for EJB applications within the application server. A
single EJB container can have one or more EJB modules. It acts as
an intermediate action between business logic and enterprise
application. The typical behavior envisioned by the Java EE
specification is that a developer writes an Enterprise JavaBean, a
simple component, and the EJB container adds the necessary
infrastructure for communications, transactions, and data access.
It turns the business logic into something that executes.

Architecture of jba
The Java Persistence API (JPA) is a specification of Java. It is used
to persist data between Java object and relational database. JPA
acts as a bridge between object-oriented domain models and
relational database systems. The jpa architecture consists of
units: 1. EntityManagerFactory-This is a factory class of
EntityManager. It creates and manages multiple EntityManager
instances. 2. EntityManager -It is an Interface, it manages the
persistence operations on objects. It works like factory for Query
instance. 3. Entity-Entities are the persistence objects, stores as
records in the database. 4. EntityTransaction-It has one-to-one
relationship with EntityManager. For each EntityManager,
operations are maintained by EntityTransaction class. 5.
Persistence-This class contain static methods to obtain
EntityManagerFactory instance. 6. Query-This interface is
implemented by each JPA vendor to obtain relational objects that
meet the criteria.

Hibernate and architecture


Hibernate is a Java framework that simplifies the development of
Java application to interact with the database. It is an open source,
lightweight, ORM (Object Relational Mapping) tool. Hibernate
implements the specifications of JPA (Java Persistence API) for
data persistence. The Hibernate architecture is categorized in
four layers : 1.Java application layer. 2. Hibernate framework
layer. 3. Backhand api layer. 4. Database layer. Elements of
Hibernate Architecture are : SessionFactory, Session, Transaction,
ConnectionProvider, TransactionFactory.

Impedance mismatch? How can it be solved


Impedance mismatch is the term used to refer to the problems
that occurs due to differences between the database model and
the programming language model. One common solution to the
impedance mismatch problem is to layer the domain and
framework logic. In this scheme, the object oriented language is
used to model certain relational aspects at runtime rather than
attempt the more static mapping.

You might also like