3.2. Advantages of JSP

JSP has a number of advantages over many of its alternatives. Here are a few of them.

Versus Active Server Pages (ASP) or ColdFusion

ASP is a competing technology from Microsoft. The advantages of JSP are twofold.

First, the dynamic part is written in Java, not VBScript or another ASP-specific language, so JSP is more powerful and better suited to complex applications that require reusable components.

Second, JSP is portable to other operating systems and Web servers; you aren’t locked into Windows and IIS. Even if ASP.NET (not yet available as of fall 2001) succeeds in addressing the problem of developing server-side code with VBScript, you cannot expect to use ASP on multiple servers and operating systems.

You could make the same argument when comparing JSP to the current version of ColdFusion; with JSP you can use Java for the “real code” and are not tied to a particular server product. Note, however, that the next release of ColdFusion (version 5.0) will be within the context of a J2EE server, allowing developers to easily mix ColdFusion and servlet/JSP code.

Versus PHP

PHP (a recursive acronym for “PHP: Hypertext Preprocessor”) is a free, open-source, HTML-embedded scripting language that is somewhat similar to both ASP and JSP. One advantage of JSP is that the dynamic part is written in Java, which already has an extensive API for networking, database access, distributed objects, and the like, whereas PHP requires learning an entirely new, less widely used language. A second advantage is that JSP is much more widely supported by tool and server vendors than is PHP.

Versus Pure Servlets

JSP doesn’t provide any capabilities that couldn’t, in principle, be accomplished with a servlet. In fact, JSP documents are automatically translated into servlets behind the scenes. But it is more convenient to write (and to modify!) regular HTML than to have a zillion println statements that generate the HTML. Plus, by separating the presentation from the content, you can put different people on different tasks: your Web page design experts can build the HTML by using familiar tools and either leave places for your servlet programmers to insert the dynamic content or invoke the dynamic content indirectly by means of XML tags.

Does this mean that you can just learn JSP and forget about servlets? By no means! JSP developers need to know servlets for four reasons:

  1. JSP pages get translated into servlets. You can’t understand how JSP works without understanding servlets.

  2. JSP consists of static HTML, special-purpose JSP tags, and Java code. What kind of Java code? Servlet code! You can’t write that code if you don’t understand servlet programming.

  3. Some tasks are better accomplished by servlets than by JSP. JSP is good at generating pages that consist of large sections of fairly well structured HTML or other character data. Servlets are better for generating binary data, building pages with highly variable structure, and performing tasks (such as redirection) that involve little or no output.

  4. Some tasks are better accomplished by a combination of servlets and JSP than by either servlets or JSP alone. See Section 3.8 (Integrating Servlets and JSP: The MVC Architecture) for details.

Versus JavaScript

JavaScript, which is completely distinct from the Java programming language, is normally used to generate HTML dynamically on the client, building parts of the Web page as the browser loads the document. This is a useful capability and does not normally overlap with the capabilities of JSP (which runs only on the server). JSP pages still include SCRIPT tags for JavaScript, just as normal HTML pages do. In fact, JSP can even be used to dynamically generate the JavaScript that will be sent to the client.

It is also possible to use JavaScript on the server, most notably on Netscape, IIS, and BroadVision servers. However, Java is more powerful, flexible, reliable, and portable.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.55.198