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

Mod 4 Assignmnt

Uploaded by

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

Mod 4 Assignmnt

Uploaded by

Viraj Kudav
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

7a.

Brief Introduction:
A servlet is a Java class which is used to extend the capabilities of servers
that host applications accessed by means of a request-response model.
Servlets are mainly used to extend the applications hosted by webs servers,
however, they can respond to other types of requests too. For such
applications, HTTP-specific servlet classes are defined by Java Servlet
technology.
A JSP is a text document which contains two types of text: static data and
dynamic data. The static data can be expressed in any text-based format
(like HTML, XML, SVG and WML), and the dynamic content can be
expressed by JSP elements.
Difference between Servlet and JSP
Servlet JSP
Servlet is a java code. JSP is a html based code.

Writing code for servlet is harder JSP is easy to code as it is java in


than JSP as it is html in java. html.

Servlet plays a controller role in JSP is the view in MVC approach for
MVC approach. showing output.

JSP is slower than Servlet because


the first step in JSP lifecycle is the
translation of JSP to java code and
Servlet is faster than JSP. then compile.

Servlet can accept all protocol


requests. JSP only accept http requests.

In Servlet, we can override the In JSP, we cannot override its


service() method. service() method.

In Servlet by default session


management is not enabled, user In JSP session management is
have to enable it explicitly. automatically enabled.

In Servlet we have to implement


everything like business logic and In JSP business logic is separated
presentation logic in just one servlet from presentation logic by using
file. javaBeans.
Modification in Servlet is a time
consuming task because it includes
reloading, recompiling and restarting JSP modification is fast, just need to
the server. click the refresh button.

7C.

JSP ARCHITECTURE

• The JSP architecture is a 3-tier architecture where each part has its own roles and
functionalities.

• The web server needs a JSP engine, i.e, a container to process JSP pages. The JSP container is
responsible for intercepting requests for JSP pages.

• A JSP container works with the Web server to provide the runtime environment and other
services a JSP needs.

JSP Architecture Flow

• As with a normal page, your browser sends an HTTP request to the web server.

• The web server recognizes that the HTTP request is for a JSP page and forwards it to a JSP
engine. This is done by using the URL or JSP page which ends with .jsp instead of .html.
• The JSP engine loads the JSP page from disk and converts it into a servlet content. This
conversion is very simple in which all template text is converted to println( ) statements and
all JSP elements are converted to Java code. This code implements the corresponding
dynamic behavior of the page.

• The JSP engine compiles the servlet into an executable class and forwards the original
request to a servlet engine.

• A part of the web server called the servlet engine loads the Servlet class and executes it.
During execution, the servlet produces an output in HTML format. The output is furthur
passed on to the web server by the servlet engine inside an HTTP response.

• The web server forwards the HTTP response to your browser in terms of static HTML
content.

• Finally, the web browser handles the dynamically-generated HTML page inside the HTTP
response exactly as if it were a static page.

8A. Advantages of Java Beans

A software component architecture provides standard mechanisms to deal with software building

blocks. The following list enumerates some of the specific benefits that Java technology provides for a

component developer:

 A Bean obtains all the benefits of Java's "write-once, run-anywhere" paradigm.


 The properties, events, and methods of a Bean that are exposed to an application
builder tool can be controlled.
 A Bean may be designed to operate correctly in different locales, which makes it
useful in global markets.
 Auxiliary software can be provided to help a person configure a Bean. This software is
only needed when the design-time parameters for that component are being set. It
does not need to be included in the run-time environment.
 The configuration settings of a Bean can be saved in persistent storage and restored
at a later time.
 A Bean may register to receive events from other objects and can generate events that
are sent to other objects.
8B

Remote Method Invocation Concept A Java object runs within a Java Virtual Machine (JVM),
which you lParned about in Part I. Likewise, a J2EE application runs within a JVM; however,
ohjf·:_.3 used by a J2EE application do not need to run on the same JVM as the J2EE
application. This is because a J2EE application and its components can invoke objects located
on a different JVM by 1:1sing the Java Remote Method Invocation (RMI) system. RMI is used
for remote communication between Java applications and components, both of which must
be \4ritten in the Java programming language. RMI .is used to connect together a client and
a server. A client is an application or component that requires the services of an object to
fulfill a request A server creates 2.n object and makes the object available to clients. A client
contacts the server to reference and invoke the object by using RMI. A client locates a
remote object by either using the RMI naming registry or by passing a string that references
the remote object. In either case, RMI returns a reference to the remote object, which is
then invoked by the client as 'if the object was on the local JVM. RMI handles transmission of
requests and provides the facility to load the object's bytecode, which is referred to as
dynamic code loading. This means that the behavior of an application can be dynamicalJy
extended by the remote JVM
Socket programming - you have to handle exactly which sockets are being used, you
specify TCP or UDP, you handle all the formatting of messages travelling between client
and server. However, if you have an existing program that talks over sockets that you
want to interface to, it doesn't matter what language it's written in, as long as message
formats match.

RMI - hides much of the network specific code, you don't have to worry about specific
ports used (but you can if you want), RMI handles the formatting of messages between
client and server. However, this option is really only for communication
between Java programs.

Architecture of an RMI Application


In an RMI application, we write two programs, a server program (resides on the
server) and a client program (resides on the client).
 Inside the server program, a remote object is created and reference of that
object is made available for the client (using the registry).
 The client program requests the remote objects on the server and tries to
invoke its methods.
The following diagram shows the architecture of an RMI application.

Let us now discuss the components of this architecture.


 Transport Layer − This layer connects the client and the server. It manages
the existing connection and also sets up new connections.
 Stub − A stub is a representation (proxy) of the remote object at client. It
resides in the client system; it acts as a gateway for the client program.
 Skeleton − This is the object which resides on the server
side. stub communicates with this skeleton to pass request to the remote
object.
 RRL(Remote Reference Layer) − It is the layer which manages the
references made by the client to the remote object.

Working of an RMI Application


The following points summarize how an RMI application works −
 When the client makes a call to the remote object, it is received by the stub
which eventually passes this request to the RRL.
 When the client-side RRL receives the request, it invokes a method
called invoke() of the object remoteRef. It passes the request to the RRL on
the server side.
 The RRL on the server side passes the request to the Skeleton (proxy on the
server) which finally invokes the required object on the server.
 The result is passed all the way back to the client.

You might also like