Towards Servlets
When a browser invokes a servlet, this is what happens.
The servlet container init() the servlet only once and for subsequent requests different threads are spawned to call the service() method of the servlet. Servlet has a mapping in a file called web descriptor or web.xml. When client requests a servlet this mapping is used to find the corresponding servlet class.
There is also something called jsps. what is the difference between a jsp and a servlet?
A very basic difference:
And here's a jsp example.
However a jsp is actually a servlet!!! It is comprised of two very specific syntax styles: scriptlet and markup – a scriptlet simply being blocks of Java code that are mixed with markup, which is the standard HTML or XML. This is what happens when a jsp is invoked by a client.
Other differences are:
Servlet Advantage
1. Servlets provide a way to generate dynamic documents that is both easier to write and faster to run.
2. provide all the powerfull features of JAVA, such as Exception handling and garbage collection.
3. Servlet enables easy portability across Web Servers.
4. Servlet can communicate with different servlet and servers.
5. Since all web applications are stateless protocol, servlet uses its own API to maintain session
Servlet Disadvantage
1. Designing in servlet is difficult and slows down the application.
2. Writing complex business logic makes the application difficult to understand.
3. You need a Java Runtime Environment on the server to run servlets. CGI is a completely language independent protocol, so you can write CGIs in whatever languages you have available (including Java if you want to).
From the earlier post I've discussed about the techniques of dynamic web content loading. This post is about servlets, java servlet pages (jsps) and java.
Java Servlets are an efficient and powerful solution for creating
dynamic content for the Web. Over the past few years Servlets
have become the fundamental building block of mainstream server-side
Java. The power behind Servlets comes from the use of
Java as a platform and from interaction with a Servlet container. The
Java platform provides a Servlet developer with a robust
API, object-orientated programming, platform neutrality, strict
types, garbage collection, and all the security features of
the JVM. Complimenting this, a Servlet container provides life cycle
management, a single process to share and manage application-wide
resources, and interaction with a Web server. Together this
functionality makes Servlets a desirable technology for server-side
Java developers.
Servlets are always part of a larger project called a Web Application. A Web Application is a complete collection of resources
for a Web site. Nothing stops a Web Application from consisting of zero, one, or multiple Servlets, but a Servlet container
manages Servlets on a per Web Application basis. Web Applications and the configuration files for them are specified by the
Servlet specification.
When a browser invokes a servlet, this is what happens.
- Read the explicit data sent by the clients (browsers). This includes an HTML form on a Web page or it could also come from an applet or a custom HTTP client program.
- Read the implicit HTTP request data sent by the clients (browsers). This includes cookies, media types and compression schemes the browser understands, and so forth.
- Process the data and generate the results. This process may require talking to a database, executing an RMI or CORBA call, invoking a Web service, or computing the response directly.
- Send the explicit data (i.e., the document) to the clients (browsers). This document can be sent in a variety of formats, including text (HTML or XML), binary (GIF images), Excel, etc.
- Send the implicit HTTP response to the clients (browsers). This
includes telling the browsers or other clients what type of document is
being returned (e.g., HTML), setting cookies and caching parameters, and
other such tasks.
This is what the servlet actually does.
The servlet container init() the servlet only once and for subsequent requests different threads are spawned to call the service() method of the servlet. Servlet has a mapping in a file called web descriptor or web.xml. When client requests a servlet this mapping is used to find the corresponding servlet class.
There is also something called jsps. what is the difference between a jsp and a servlet?
A very basic difference:
- Servlet is [
html] in java
- JSP is
java in [html]
And here's a jsp example.
However a jsp is actually a servlet!!! It is comprised of two very specific syntax styles: scriptlet and markup – a scriptlet simply being blocks of Java code that are mixed with markup, which is the standard HTML or XML. This is what happens when a jsp is invoked by a client.
Other differences are:
- JSP is a webpage scripting language that can generate dynamic content while Servlets are Java programs that are already compiled which also creates dynamic web content
- Servlets run faster compared to JSP
- JSP can be compiled into Java Servlets
- It’s easier to code in JSP than in Java Servlets
- In MVC, jsp act as a view and servlet act as a controller.
- JSP are generally preferred when there is not much processing of data required. But servlets are best for use when there is more processing and manipulation involved.
- The advantage of JSP programming over servlets is that we can build custom tags which can directly call Java beans. There is no such facility in servlets.
- We can achieve functionality of JSP at client side by running JavaScript at client side. There are no such methods for servlets.
Servlet Advantage
1. Servlets provide a way to generate dynamic documents that is both easier to write and faster to run.
2. provide all the powerfull features of JAVA, such as Exception handling and garbage collection.
3. Servlet enables easy portability across Web Servers.
4. Servlet can communicate with different servlet and servers.
5. Since all web applications are stateless protocol, servlet uses its own API to maintain session
Servlet Disadvantage
1. Designing in servlet is difficult and slows down the application.
2. Writing complex business logic makes the application difficult to understand.
3. You need a Java Runtime Environment on the server to run servlets. CGI is a completely language independent protocol, so you can write CGIs in whatever languages you have available (including Java if you want to).
Comments
Post a Comment