38
Chapter 4 Using Servlets and JSP
Using Java Servlets
Java Servlets are server-side components written in Java that let you add custom
functionality to a web server. A servlet runs on a web server and features high
performance, database connectivity, stability, and security.
Unlike CGI scripts, which are often written in C++ and Perl for a specific web server
implementation, servlets are written in Java and, therefore, include all the benefits of the
Java programming language, including portability—the “write once, run anywhere”
feature of Java.
Servlets are ideally suited for web-based applications because they support the HTTP
request/response protocol. The following figure shows the basic processing model of a
Java Servlet:
As you can see in this figure, the web server receives the HTTP request, determines that
the request references a servlet, and forwards the request to the servlet engine, which
invokes the appropriate servlet. The servlet processes the request and returns a response
that the web server then forwards back to the client.
You can use servlets to write sophisticated applications without being encumbered by the
complexities and platform-specific behaviors of a specific web server implementation.
The servlet API supports the building blocks of a web application, such as HTML, form
data, request headers, and cookies.
Invoking servlets
A client invokes a servlet by referencing a URL, as it would any web resource. The fact
that a URL references a servlet is transparent to the web client.
Typically, a client invokes a servlet in one of the following ways:
•
By accessing a JavaServer Page
JavaServer Pages (JSPs) are a combination of
HTML and scripting code (typically written in Java or JavaScript). The first time a
client accesses a JSP file, JRun translates the file into Java source code, compiles the
source-code into a Java Servlet, and then loads and executes the servlet. The web
server forwards any HTML output from the servlet back to the web client.
Subsequent client accesses to the JSP file are very efficient because the servlet
executable remains in memory. This means JRun can reference the servlet image in
memory, and bypass the compile and load steps.
•
By directly referencing a URL that is mapped to a servlet
The servlet remains in
memory, and subsequent calls to the servlet reference the memory image.
Содержание 38000382 - Macromedia JRun - Mac
Страница 1: ...Getting Started with JRun...
Страница 16: ......
Страница 68: ...54 Chapter 5 Introduction to EJB...
Страница 82: ......
Страница 110: ...96 Lesson 3 EJB Tutorial...
Страница 128: ...114 Lesson 4 Web Services Tutorial...
Страница 132: ...118 Index...