Introduction of Servlets
- Servlets is Web Technology which is used to develop the Applications and provided by Sun MicroSystem.
- Web Application is a type of application in which whole application will be on a server machine and the client will access the application using a browser.
- To develop Web Applications you need to develop client-side component as well as Server side Component.
- Client side component can be developed using HTML/JSP/XHTML etc.
- Server side component can be developed using Servlet/Jsp/Filter etc.
If you want to develop Web Application then it can be of two types:
- Static Web Application
- Dynamic Web Application
Static Web Application: In this type of application, a view will be the same for all the client and client cannot interact with the application by sending some data to the server for processing.
Dynamic Web Application: In this type of application, a client can send the data to a server and that data will be processed and depending on the processing the response will be given to client so the view of application will vary from client to client.
Servlet can be used for developing Web Application. Servlets is server side component which receives the Request from a browser, processes the request and sends the response to the browser.
Types of Applications Java Servlet:
- Standalone Applications
- Client-Server Applications
- Web Applications
- Distributed Applications
- Enterprise Applications
1. Standalone Applications:
Applications that can be accessed by a single user at a time are called Standalone Applications. Ex: MS-Word, Music Player etc.
- Standalone Applications can be implemented using c, c++, and Java etc.
- Applications have to be installed across all the machines. This may give maintenance when you change application features.
- Data sharing is not possible.
2. Client-Server Application:
In this case of Client-Server Application, an application can be divided into two parts. One part will be installed on the server Machine and other parts will be installed on multiple client machines i.e. multiple clients can access the centralized server.
Ex. Yahoo Messenger Talk etc.
- Client-Server Applications can be implemented using C, C++, and Java etc.
- Data sharing is possible
Problems: Client software has to install across all the machines. This may give maintenance when you change client software features.
3. Web Applications:
To solve the problem with client-server application Web-based application is introduced which is run in WWW. In this case of Web Applications, Application software will be installed on the Web Server Machine only. i.e. multiple clients can access the centralized web server using any web browser.
- Web Applications can be implemented using Servlets, JSP, Struts and JSF etc.
- Data sharing is possible
- No Maintenance problem because modifications will happen only at the Web server.
4. Distributed Application:
Distributed Application is a current trend in a company which allows the business partner to share the information among them.
5. Enterprise Application:
An enterprise application is a term used to describe applications or software that a business would use to assist the organization in solving enterprise problem. When the word “enterprise” is combined with “application”, it usually refers to a software platform that is too large and too complex for an individual or small business use.
Enterprise applications are typically designed to interface or integrate with other enterprise applications used within the organization, and to be deployed across a variety of networks(Internet, Intranet and corporate networks) while meeting strict requirements for security and administration management.
When you hit the browser with some URL. The first request will be given to DNS server. In DNS server domain will be resolved of IP address and a request will be sent to the server where an application is running. Once the server receives the request it processes the request and sends the response to the client. Servers identify the client IP address from the Http request.
- Web Server
- Web Client
- Web Container
- Web Application
- Web Technologies
- Web Frameworks
Web server is an application which receives the Http Request from Client and processes that request with the help of Container and send the response to a client.
Ex: Apache Server, PWS (ASP), IIS
This is an application which sends the Http Request to Web Server and receives the response from Server.
Ex: IE, Opera, Mozilla etc.
This is an application is responsible for managing the complete lifecycle of Servlet or JSP.
Web container offers the following free services:
1. Low-Level Services
a) IO Streams
2. Middle-Level Services
a) Resource Management
b) Lifecycle Management
c) Declarative Security Management
d) JSP Lifecycle support
3. High-Level Services
As a developer, you have to write the code only for High-Level Services(Business operations of an application which you are developing.
Http(Hyper Text Transfer Protocol): Http sits on the top of TCP/IP for transferring Client into Server info to Client.
TCP/IP: Original data transfer will happen through TCP/IP. IP(Internet Protocol) is responsible for carrying data from one place to another. TCP(transport Control protocol) sits on the top of the IP and monitors the Data Transmission.
DNS: Domain Naming Service is a registry where domain names will be bound with IP address.
Web Technologies: Servlets and JSP.
Web Frameworks: Struts, JSP, SpringMVC etc are the web frameworks
- Parameters are name-value pair.
- Parameter Name and Parameter value are of type String only.
- Parameters are Read-only. We can’t change the request data.
There are 3 types of Parameters:
- ServletRequest parameters
- ServletConfig parameters
- ServletContext parameters
1) Servlet Request Parameters: Client submitted data coming from the web client (Browser) to Server(Apache) along with Http Request are called as Request Parameters
Web container collects client submitted data and stores that in HttpServeltRequest object as Request parameters.
As a developer, you can collect that data from the request object as follows:
String un= request.getParameter(“name”);
2) ServletConfig Parameters: If you want to use any data which is common for all the users and specific to a particular servlet, that data can be specified as config parameters in the web.xml as follows:
<servlet> ... <init-param> <param-name>email</param-name> <param-value>[email protected]</param-value> </init-param> <servlet>
Web container collects data from web.xml and stores that in ServletConfig object as Config parameters.
As a Developer, you can collect that data from the config object as follows;
String en= config.getInitParameter(“email);
Note: Every Servlet will have its own ServletConfig object and cannot be shared.
3) ServletContext parameters: If you want to use any data which is common for all the users and common to all the servlets, that data can be specified as Context parameters in the Web.xml as follows;
<context-param> <param-name>city</param-name> <param-value>Noida</param-value> </context-param>
Web Container collects data from web.xml and stores that in ServletContext object as context parameters. As a developer, you can collect that data from the context object as follows:
String ci= context.getInitParameter(“city”);
All the servlets will have only one ServletContext object and can be shared with all the servlets running in the container. i.e One Web application will have one ServletContext object.
In this article, we learned regarding the introduction of the servlets and regarding the web applications and its type. Please, feel free to drop a comment in the below comment box if you have any doubt regarding the topic or you want to share any information about the topic. Happy Learning!
READ NOW :- Java Annotations