Pure JSP : Java Server Pages

Pure JSP : Java Server Pages

by James Goodwill
     
 

Pure JSP gives a very concise conceptual overview of the JavaServer Pages technology and its related components. Once you have a firm foundation with the JSP technology, related topics such as JavaBeans, JDBC and Servlets are covered at a very high level. The book moves on to explain a large number of JSP techniques, which were determined by studying problems faced…  See more details below

Overview

Pure JSP gives a very concise conceptual overview of the JavaServer Pages technology and its related components. Once you have a firm foundation with the JSP technology, related topics such as JavaBeans, JDBC and Servlets are covered at a very high level. The book moves on to explain a large number of JSP techniques, which were determined by studying problems faced by JSP users in the professional world. The final section covers the more technical aspects of the JSP technology. Topics include related API's, server configuration, and charts and diagrams related to developing JSP applications.

Editorial Reviews

Booknews
A reference for Java Server Pages developers containing an accelerated introduction to concepts and implementation, and information on such topics as JavaBeans, JDBC, and Servlets. Goodwill, the chief Internet architect of a high-tech Denver company, also offers many complete and highly commented programs that demonstrate the implementation techniques and can be downloaded from the web. He does not provide a bibliography. Annotation c. Book News, Inc., Portland, OR (booknews.com)

Product Details

ISBN-13:
9780672319020
Publisher:
Pearson Education
Publication date:
06/08/2000
Series:
Sams Professional Series
Pages:
320
Product dimensions:
6.00(w) x 9.06(h) x 0.70(d)

Read an Excerpt


Chapter 2: Java Servlets

JavaServer Pages are extensions of Java servlets, therefore, you really need to understand Java servlets before you can fully grasp the JSP architecture. Given the previous statement, servlets are generic extensions to Java-enabled servers. Their most common use is to extend Web servers, providing a very efficient, portable, and easy-to-use replacement for CGI. A servlet is a dynamically loaded module that services requests from a Web server. It runs entirely inside the Java Virtual Machine. Because the servlet is running on the server side, it does not depend on browser compatibility. Figure 2.1 depicts the execution of a Java servlet. In this chapter, you'll learn the basics of working with servlets, and how servlets fit into the framework of JSP.

Practical Applications for Java Servlets

Servlets can be used for any number of "Web-related" applications. When you start using servlets, you will find more practical applications for them. The following list contains three examples that I believe are some of the most important applications:

  • Developing e-commerce "storefronts" will become one of the most common uses for Java servlets. A servlet can build an online catalog based on the contents of a database. It can then present this catalog to the customer using dynamic HTML. The customer will choose the items to be ordered, enter the shipping and billing information, and then submit the data to a servlet. When the servlet receives the posted data, it will process the orders and place them in the database for fulfillment. Every one of these processes can easily be implemented using Java servlets.

  • Servlets can be used to deploy Web sites that open up large legacy systems on the Internet. Many companies have massive amounts of data stored on large mainframe systems. These businesses do not want to reengineer their systems' architecture, so they choose to provide inexpensive Web interfaces into the systems. Because you have the entire JDK at your disposal and security provided by the Web server, you can use servlets to interface into these systems using anything from TCP/IP to CORBA.

  • When developing a distributed object application that will be deployed to the Web, you run into access issues. If you choose to use applets in your client browser, you are only able to open a connection to the originating server, which might be behind a firewall. Getting through a firewall using Remote Method Invocation (RMI) is a very common problem. If servlets are employed, you can tunnel through the firewall using a servlet technology called HTTPTunneling. This enables the applet to access objects that can be running almost anywhere on the network.

These are just a few examples of the power and practicality of using Java servlets. Servlets are a very viable option for most Web applications.

The Java Servlet Architecture

Two packages make up the servlet architecture: the javax.servlet and javax.servlet.http packages. The javax.servlet package contains the generic interfaces and classes that are implemented and extended by all servlets. The javax. servlet. http package contains the classes that are extended when creating HTTP-specific servlets. An example of this would be a simple servlet that responds using HTML.

At the heart of this architecture is the interface javax.servlet.Servlet. It provides the framework for all servlets. The Servlet interface defines five methods. The three most important are as follows:

  • init ( ) method-Initializes a servlet

  • service () method-Receives and responds to client requests

  • destroy() method-Performs cleanup

All servlets must implement this interface, either directly or through inheritance. It is a very clean object-oriented approach that makes the interface very easy to extend. Figure 2.2 is an object model that gives you a very high-level view of the servlet framework.

GenericServlet and HttpServlet

The two main classes are the GenericServlet and HttpServlet classes. The HttpServlet class is extended from GenericServlet. When you are developing your own servlets, you will most likely be extending one of these two classes. If you are going to be creating Web Applications, then you will be extending the HttpServlet class. Java servlets do not have a main () method, which is why all servlets must implement the j avax. se rvlet . Servlet interface. Every time a server receives a request that points to a servlet, it calls that servlet's service( ) method.

If you decide to extend the GenericServlet class, you must implement the service() method. The GenericServlet. service() method has been defined as an abstract method in order to force you to follow this framework. The service() method prototype is defined as follows...

Read More

Meet the Author


James Goodwill is the Chief Internet Architect and a Principal at Virtuas Solutions, Inc., located in Denver, Colorado. He has extensive experience in telecommunications and e-business applications. James is also the author of Developing Java Servlets, which provides a thorough look at Java Servlets. Over the last several years he has been focusing his efforts on the design and development of electronic commerce applications.

Customer Reviews

Average Review:

Write a Review

and post it to your social network

     

Most Helpful Customer Reviews

See all customer reviews >