Java Reference
In-Depth Information
3. Enter lines 68 through 89 as shown in Figure 12-7 on page 788. Save
the file again by clicking the Save button on the Standard toolbar.
TextPad displays HTML statements in the coding window for two buttons
(Figure 12-13). The Log on button calls the JavaScript validate() function
when clicked, passing a reference to the current form, logonScreen. The
reset button, which will display the label Clear, resets all input data fields on
the form. The code inserts an image that displays in the third table column.
button label
set to Log on
creates button
button label
set to Clear
creates reset
button
inserts image
in rightmost
table column
FIGURE 12-13
The code for the Web page, index.html, is complete. Because HTML source
code is loaded and interpreted by a browser, you do not compile it as you would
Java source program.
Creating a Servlet
The code in line 39 of the initial Web page, index.html, sends form data to a
servlet named WebStocks. As previously noted, a running Java Web application
depends on many components, including servlets and JavaServer Pages. Recall that
a servlet is a Java class that runs on a Web server, rather than being launched from
a browser. Instead, the servlet is loaded into and runs inside a servlet container
running on the Web server. A servlet and JSP container is software that allows a
Web server to work with servlets and JavaServer Pages. The container actually
comprises two containers, one for processing servlets and one for JSPs, and often
is referenced as a servlet container or JSP container, depending on the purpose
being served. As you will learn later in this project, the Tomcat Web server is both
a servlet container and a JSP container, and also can function as a Web server.
Java Servlet Processing
A servlet receives and responds to requests from clients, such as a Web
browser. A servlet using HTTP extends the HttpServlet class, which provides
access to HTTP request and HTTP response objects. These objects encapsulate
HTTP requests and responses, respectively, so they can be accessed easily within
the servlet.
 
Search WWH ::




Custom Search