Mod 4 Assignmnt
Mod 4 Assignmnt
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.
Servlet plays a controller role in JSP is the view in MVC approach for
MVC approach. showing output.
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.
• 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.
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:
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.