eWebProgrammer eweb





Java Servlets   «Prev  Next»
Lesson 1

Introduction to Java Servlets and the Java Servlet API

The Java Servlet API allows a software developer to add dynamic content to a Web server using the Java platform. The generated content is commonly HTML, but may be other data such as XML.
Servlets are the Java counterpart to non-Java dynamic Web content technologies such as PHP, CGI and ASP.NET.
Servlets can maintain state across many server transactions by using HTTP cookies, session variables or URL rewriting.

In this module you will review how HTTP works to get information from a Web server to a user.
One of the most important aspects of HTTP:
Every request to a Web server is completely independent of the previous ones.
We will discuss three other major server side technologies and what a servlet is and how it functions.
Ater completing this module, you will be able to:
  1. Describe how a Web browser requests information from a Web server
  2. Describe how a Web server provides information to a Web browser
  3. List some features of CGI
  4. List some features of SSI
  5. List some features of ASP
  6. Compare servlets to other server-side technology
  7. Describe what a servlet is



Powerful

Servlets support several capabilities that are difficult or impossible to accomplish with regular CGI. Servlets can talk directly to the Web server, whereas regular CGI programs cannot, at least not without using a server-specific API. Communicating with the Web server makes it easier to translate relative URLs into concrete path names, for instance. Multiple servlets can also share data, making it easy to implement database connection pooling and similar resource-sharing optimizations. Servlets can also maintain information from request to request, simplifying techniques like session tracking and caching of previous computations.

Portable

Servlets are written in the Java programming language and follow a standard API. Servlets are supported directly or by a plugin on virtually every major web server. Consequently, servlets written for Tomcat can run virtually unchanged on Microsoft Internet Information Server (with a separate plugin), IBM WebSphere, or Oracle WebLogic Server 12c.
They are part of the Java 2 Platform, Enterprise Edition (J2EE; https://www.oracle.com/technetwork/java/javaee/overview/index.html), so industry support for servlets is becoming even more pervasive.

Inexpensive

A number of free or very inexpensive Web servers are good for development use or deployment of low- or medium-volume websites. Thus, with servlets and JSP you can start with a free server and migrate to more expensive servers with high-performance capabilities or advanced administration utilities only after your project meets initial success. This is in contrast to many of the other CGI alternatives, which require a significant initial investment for the purchase of a proprietary package.
Buying a special-purpose Web server from a U.S. company consumes a large part of early project funds. But, with servlets and JSP, you can start with a free server known as Apache Tomcat. Once the project starts to become successful, they could move to a server like Caucho Resin that has higher performance and easier administration but that is not free. But none of their servlets or JSP pages have to be rewritten. If their project becomes even larger, they might want to move to a distributed (clustered) environment. Again, none of their servlets or JSP pages have to be rewritten. If the project becomes quite large and complex, they might want to use Enterprise JavaBeans (EJB) to encapsulate their business logic. So, they might switch to Oracle WebLogic or IBM Websphere. Finally, if their project becomes even bigger, they might move it off of their Linux box and onto
AWS or Google Cloud.