Have you ever wanted to develop JSP Web applications? This article will help you get all the tools you need installed on your computer, and walk you through the process of writing a simple application. It is excerpted from the book Beginning JSP 2 From Novice to Professional, written by Peter den Haan et al (Apress, 2004; ISBN: 1590593391).
Creating Your First JSP Page - Java and the Web (Page 6 of 7 )
At last we come to Java. Java was initially released in the mid-1990s as a way to liven up dull, static Web pages. It was platform-independent (the same Java code can run on computers running a variety of different operating systems rather than being tied to just one), and it allowed developers to have their programs execute in the Web browser. Many an industry sage prognosticated that these Java applets (applet being a “mini-application” that executes within another application—the browser) would catch on, making the Web more exciting and interactive and changing the way people bought computers, reducing all the various operating systems into mere platforms for Web browsers (see Figure 1-5).
Figure 1-5.A Java applet in action
NOTE Figure 1-5 shows one of many applets available at http://java.sun.com/applets/.If you enter the URL shown in Figure 1-5, don’t forget to capitalize it as it appears.
However, Java applets never really caught on to the degree people predicted, and other technologies such as Macromedia Flash became more popular ways of creating interactive Web sites. However, Java isn’t just good for applets: You can also use it for creating stand-alone platform-independent applications. Although these too could threaten the monopolies of entrenched incompatible operating systems, Java applications haven’t really caught on yet either. This is probably because Java’s support for creating graphical user interface (GUI) applications—applications with windows, icons, buttons, and so on—has until recently been quite poor and slow. This situation is changing; in fact, today’s versions of Java enable developers to create cutting-edge GUI applications.
But like a prizefighter who won’t stay down, those innovative Java architects kept on fighting, releasing Java servlets into the arena. Servlets (“mini-servers”) are another alternative technology to CGI. Servlets aren’t stand-alone applications, and they must be loaded into memory by a servlet container. The servlet container then functions as a Web server, receiving HTTP requests from Web browsers and passing them to servlets that generate the response, typically an HTML document. Alternatively, the servlet container can integrate with an existing Web server; for example, a popular Apache module, called a connector and found on the Tomcat Web site, integrates Apache with the Tomcat servlet container.
The simplicity of the Java programming language, its platform-independent nature, Sun’s open-source and community-driven attitude toward Java, and the elegance of the servlet model itself have all made servlets an immensely popular solution for providing dynamic Web content.
To make creating dynamic Web content even easier, Sun introduced JSP. Although writing servlets can require extensive knowledge of Java, a Java newbie can learn some pretty neat tricks in JSP in a snap. JSP represents a viable and attractive alternative to Microsoft’s ASP.
NOTE JSP technology is actually built on top of servlets. As you’ll see later in the book, the two technologies actually work well together, and it’s common to use both in the same Web application.
More About Servlet Containers
As mentioned earlier, JSP and servlets require a special kind of server to operate: a servlet container. Tomcat, which you installed earlier, is known as a reference implementation of a JSP servlet container, but this isn’t to say it’s not worthy of use in production systems. Indeed, many commercial installations use Tomcat, but many other servlet containers are available. These include Caucho Resin (http://www.caucho.com), which is very popular and somewhat faster than Tomcat but is a commercial product that must be purchased. Jetty (http://jetty.mortbay.org) is perhaps the most popular open-source competitor, and there are many alternatives.