Eclipse Java servlet API tutorial for beginners and professionals with examples on Basics, Life Cycle, Servlet Examples, Client Request, Server Response, Deployment Descriptor, Request Dispatcher, Http Codes, Servlet Filters, Cookies, Sessions and more.
Web Application:
A web application or website is an application program which accessed over a network connection using HTTP and often runs inside a web browser.
Web Browser:
A web browser is a program that acts as an interface between the user and a web application e.g. Internet Explorer, Chrome, Safari, Mozilla Firefox, etc.
CGI (Common Gateway Interface):
CGI was the first protocol or way of communication between the web server and the program. It passes a request from a web user to an application program and receives data back to forward to the web user i.e. It is responsible for dynamic content generation.
Advantages of CGI:
- Technology portability: CGI programming can be written in a variety of languages like c, c++, and Perl.
- Web server portability: All service providers support CGI Programs.
Disadvantages:
- Response time is high.
- CGI scripts are platform-dependent.
- For every request, a new process will be started and the web server is limited to start processes.
- CGI programs are not object-oriented always.
Servlet overcomes the above disadvantages.
Servlet as Technology:
As a technology servlet provides a model of communication between a web user request and the application or program on the web server.
Servlet as Component:
A component servlet is a program that is executed in a web server and is responsible for dynamic content generation.
Main tasks of a Servlet:
- Read the implicit and explicit data sent by the web browser.
- Generate results by processing the data.
- Send the implicit and explicit data as a response to the web browser.
Servlet Packages:
javax.servlet and javax.servlet.http packages contain the classes and interfaces for servlet API. These packages are the standard part of Java’s enterprise edition.
javax.servlet contains several classes and interfaces that are mainly used by servlet containers.
javax.servlet.http contains many classes and interfaces which are mainly used by http protocol.
Differences between CGI and Servlet.
CGI | Servlet |
|
|
Java Servlet tutorial:
- Servlet Life cycle
- Servlet interface in java
- GenericServlet class in java
- Java HttpServlet Class
- Servlet Deployment Descriptor
- Servlet welcome-file-list
- load-on-startup in web.xml
- Servlet RequestDispatcher interface
- Servlet sendRedirect
- Servlet Init parameters and ServletConfig interface
- Servlet context parameters and ServletContext interface
- Servlet Hello World Example using annotation
- Session management in servlet
- Cookie in servlet
- Servlet Hidden fields
- URL rewriting in servlet
- Servlet HttpSession
- Java Servlet filter
- Java FilterConfig interface
- java servlet example in eclipse
- The type javax.servlet.ServletException cannot be resolved. It is indirectly referenced from required .class files
- The superclass “javax.servlet.http.HttpServlet” was not found on the Java Build Path