Presentation Transcript
Slide 1:SERVLETS OVERVIEW
A servlet is a generic server extension
a Java class that can be loaded dynamically to expand the functionality
of a server.
Commonly used with web servers,
Taking the place of CGI scripts
Similar to a proprietary server extension, except:
it runs inside a Java Virtual Machine (JVM) on the server
so it is safe and portable.
handled by separate threads within the web server process
efficient and scalable
Operate solely within the domain of the server
unlike applets, they do not require support for Java in the web browser.
Slide 2:A CLOSER LOOK AT A SERVLET
A Java class that extends HttpServlet
Compiled and placed in the appropriate directory (more
on that later)
When a request for a servlet arrives, the servlet container
(a JVM):
checks if an instance of that servlet exists
if not, it creates/loads an instance
calls the servlet’s service() method (which in turn may call
doGet()/doPost()/doXXX())
Slide 3:COMPARISONS WITH CGI/FASTCGI
CGI/FastCGI:
use multiple processes to handle separate programs and/or
separate requests
Outside the server
Servlets:
handled by separate threads within the web server process.
Thus more efficient and scalable.
can interact very closely with the server to do things that are
not
Slide 4:COMPARISONS WITH CGI/FASTCGI (CONT)
Java Servlets are portable:
across operating systems (java)
across web servers, since all major web servers support servlets.
Thus, Java servlets offer a good platform for web-application
development
Slide 5:SERVLET SUPPORT
Like Java, servlets were designed for portability.
Servlets are part of the Java language, but not part of the core Java API.
Slide 6:TOOLS YOU NEED
Java Development Kit (JDK)
Java Servlet Development Kit (JSDK)
include packages:
javax.servlet
javax.servlet.http
available from
http://java.sun.com/products/servlet
Servlet Engine
Slide 7:SERVLET ENGINES
Used to test and deploy your servlets
How to choose a servlet engine you need?
Depends on the web server(s) you are running
Three kinds of servlet engines:
standalone
add-on
embeddable
Slide 8:SERVLET ENGINES
Standalone servlet engines
built-in support for servlets
hard to keep on with the latest version of servlet
Add-on servlet server engines
plug-in to an existing server
Embeddable servlet engines
lightweight servlet-deployment platform that can be embedded in another application
Slide 9:SERVLET BASICS
Java servlets are the first standard extension
to Java, including two packages:
javax.servlet
javax.servlet.http
Slide 10:SERVLET PACKAGE FRAMEWORK