Home > Articles

Using Servlet Functionality with JSP

📄 Contents

  1. Chapter 3: Using Servlet Functionality with JSP
  2. Looking at an Example Servlet
  3. The End of the Beginning
  • Print
  • + Share This
This chapter is from the book

In This Chapter

  • Moving from CGI to Servlets
  • Looking at an Example Servlet
  • The End of the Beginning

Servlets are the objects that make things happen in a JSP application. As you've seen, even a plain JSP is really a servlet in disguise (or, rather, it is turned into a servlet by the JSP engine). In this chapter, you'll learn how to access the functionality of servlets from your JSP code and Beans.

Moving from CGI to Servlets

Servlets represented the second step that Java-enabled Web servers took away from the old CGI paradigm. In CGI-based Web programming, the CGI program was an external program run by the server. It took input from environment variables and the standard input stream, and it sent its response back via standard output.

CGI-based designs worked well for quite a long time, but they had a number of problems. For one thing, a significant processing cost was associated with spawning a new process each time a CGI request came in. In addition, it was extremely difficult to carry persistent data around because each process started fresh.

The first step was to allow designers to link their own libraries into the running server binary (under Netscape, this was called NSAPI, for example). This not only drastically increased performance, but it also allowed the code to gain access to internal server functionality.

Java servlets were developed to provide the best of both worlds. Because the Java servlet runtime was persistent and lived close to the Web server, it could interact with Web requests at a detailed level. But because it was Java, it was easy to firewall potential crashes off the server itself by catching exceptions at the top level of the servlet loop.

Also, because the servlet classes are standard, servlet code will run without modification (usually) on any Java-enabled Web server.

  • + Share This
  • 🔖 Save To Your Account