Home > Articles

  • Print
  • + Share This
This chapter is from the book

This chapter is from the book

1.3 The Power of Java

JSP inherits many of its advantages from the underlying Java programming language and Java servlet technology. It also has advantages over alternate methods of development by integrating into the component model. Beyond these advantages, the JSP specification is extremely well designed, enabling extensibility and integration with other languages and specifications.

1.3.1 Write Once, Run Anywhere

Because JSP utilizes the Java programming language, it automatically has many advantages. First and foremost is the high level of portability offered by Java's well-defined and accepted API. A JSP page developed on one platform can be deployed on a large number of systems. For example, a JSP page developed on a Windows NT system tested on the JSP Reference Implementation can be easily deployed on a Linux box running Allaire Software's JRun Application Server.

Further, JSP avoids the few troublesome areas of crossplatform Java development. Since JSP pages run on the server, applications do not need to be tested with several different client platforms, as is often necessary with Java applets. The sometimes troublesome GUI systems developed in Java, such as AWT and Swing, are also avoided in JSP.

1.3.2 The Java API

Probably one of the first things you'll notice when writing JSP is that you have the full power of the Java API. The core Java API offers the power of networking, multithreading, database connectivity, internationalization, image manipulation, object serialization, remote method invocation, CORBA access, and more. Standard extensions to Java, such as the Java Naming and Directory Interface (JNDI) and the Java Mail API, offer powerful extensions to Web applications.

With the Java classes, JavaBeans™, and Enterprise Java Beans™ (EJB) components offered by numerous software vendors, it is easy to add powerful code to Web applications. Using the JavaBeans component framework, JSP can form the presentation layer of multitier applications.

JSP can be written to communicate directly to applets, allowing the same code to be leveraged on both the server and client. This opens a whole new world of client/server application development.

1.3.3 Security and Safety

Another advantage inherited from the Java programming language is strong type safety. Unlike common scripting languages, JSP and the underlying Java Servlet API manipulate data in their native types instead of strings. Java also avoids many memory issues with automatic garbage collection and the absence of pointers.

Java is also known for its excellent exception handling. When an error occurs, JSP can safely catch the exception and notify the user, instead of potentially crashing the server. This built-in feature is considered far superior to the add-on extensions and modules often implemented in other Web application environments.

Finally, a Java application server can utilize the Java security manager, protecting itself from poorly written JSP that could potentially affect server performance or damage the host file system. The Java security manager controls rights to resources that could be used to damage the system, only allowing processes with the proper rights to gain access to protected resources. This is a fundamental part of the Java programming language.

1.3.4 Scalability

The Java programming language, as well as the Java Servlet API, adds several scalability components to JSP. After a JSP page is loaded, it generally is maintained in memory. When a new request comes in for the JSP page, the server makes a simple method invocation. This is very different from traditional CGI applications, which often spawn a process and an interpreter for every request. The underlying server handles multiple requests concurrently by utilizing separate threads, making JSP highly scalable.

When integrated into the JavaBean component framework, JSP becomes even more scalable. For example, a JDBC JavaBean can handle multiple requests from JSP and maintain a single, efficient connection to the back-end database. This is especially efficient when integrated with Enterprise JavaBeans, which add transaction and security services to Web applications, as well as middleware support for Java components.

1.3.5 Extensibility

Another area where JSP often outshines its competitors is in its extensibility. The JSP specification itself is an extension of the Java servlet extension. Within JSP, the specification can be extended to create custom tags. These tags allow the JSP "language" to be extended in a portable fashion. One good idea, for example, would be to create a custom tag library filled with embedded database queries. By making these tag libraries portable, and by giving them a common interface, JSP can express the component model internally.

The JSP specification authors also left room for further extensibility by making the elements utilized by JSP independent of any certain scripting language. Currently the JSP specification only supports the Java programming language for scripting, but JSP engines can choose to support other languages.

JSP's close relationship to the Extensible Markup Language (XML) is also very important, due to the extensibility and highly organized structure of XML. A properly formed JSP page can actually be written as a valid XML document. Simple XML generation can be done in JSP by using static templates. Dynamic XML generation can be done with custom tag components, JavaBeans, or Enterprise JavaBean components. XML can also be received as request data and sent directly to custom tag components, JavaBeans, or Enterprise JavaBean components.

1.3.6 Components

An extremely powerful feature of JSP is its ability to integrate into the JavaBean component framework. This opens the door for large-scale, enterprise applications created by development teams. As Web applications become more complex, utilizing the component nature of JSP helps break down the complex tasks into simpler, manageable modules. JSP helps separate presentation logic from business logic, and allows the separation of static and dynamic data.

Because of this component-centric nature, both Java programmers and non-Java programmers alike can utilize JSP. It allows Java programmers to make and use JavaBeans, and to create dynamic Web pages utilizing fine control over those beans. Non-Java programmers can use JSP tags to connect to Java-Beans created by experienced Java developers.

  • + Share This
  • 🔖 Save To Your Account