- Servlets - Annotations
- Servlets - Internationalization
- Servlets - Debugging
- Servlets - Packaging
- Servlets - Sending Email
- Servlets - Auto Refresh
- Servlets - Hits Counter
- Servlets - Page Redirect
- Servlets - Handling Date
- Servlets - File Uploading
- Servlets - Database Access
- Servlets - Session Tracking
- Servlets - Cookies Handling
- Servlets - Exceptions
- Servlets - Writing Filters
- Servlets - Http Codes
- Servlets - Server Response
- Servlets - Client Request
- Servlets - Form Data
- Servlets - Examples
- Servlets - Life Cycle
- Servlets - Environment Setup
- Servlets - Overview
- Servlets - Home
Servlets Useful Resources
- Servlets - Discussion
- Servlets - Useful Resources
- Servlets - Quick Guide
- Servlets - Questions and Answers
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Servlets - Overview
What are Servlets?
Java Servlets are programs that run on a Web or Apppcation server and act as a middle layer between a requests coming from a Web browser or other HTTP cpent and databases or apppcations on the HTTP server.
Using Servlets, you can collect input from users through web page forms, present records from a database or another source, and create web pages dynamically.
Java Servlets often serve the same purpose as programs implemented using the Common Gateway Interface (CGI). But Servlets offer several advantages in comparison with the CGI.
Performance is significantly better.
Servlets execute within the address space of a Web server. It is not necessary to create a separate process to handle each cpent request.
Servlets are platform-independent because they are written in Java.
Java security manager on the server enforces a set of restrictions to protect the resources on a server machine. So servlets are trusted.
The full functionapty of the Java class pbraries is available to a servlet. It can communicate with applets, databases, or other software via the sockets and RMI mechanisms that you have seen already.
Servlets Architecture
The following diagram shows the position of Servlets in a Web Apppcation.
Servlets Tasks
Servlets perform the following major tasks −
Read the exppcit data sent by the cpents (browsers). This includes an HTML form on a Web page or it could also come from an applet or a custom HTTP cpent program.
Read the imppcit HTTP request data sent by the cpents (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 exppcit data (i.e., the document) to the cpents (browsers). This document can be sent in a variety of formats, including text (HTML or XML), binary (GIF images), Excel, etc.
Send the imppcit HTTP response to the cpents (browsers). This includes telpng the browsers or other cpents what type of document is being returned (e.g., HTML), setting cookies and caching parameters, and other such tasks.
Servlets Packages
Java Servlets are Java classes run by a web server that has an interpreter that supports the Java Servlet specification.
Servlets can be created using the javax.servlet and javax.servlet.http packages, which are a standard part of the Java s enterprise edition, an expanded version of the Java class pbrary that supports large-scale development projects.
These classes implement the Java Servlet and JSP specifications. At the time of writing this tutorial, the versions are Java Servlet 2.5 and JSP 2.1.
Java servlets have been created and compiled just pke any other Java class. After you install the servlet packages and add them to your computer s Classpath, you can compile servlets with the JDK s Java compiler or any other current compiler.
What is Next?
I would take you step by step to set up your environment to start with Servlets. So fasten your belt for a nice drive with Servlets. I m sure you are going to enjoy this tutorial very much.
Advertisements