When implementing topology 1 Web applications, we recommend the following technology options:
- JavaScript
- JSPs and servlets
- Command beans
- JDBC and SQLJ
JavaScript
JavaScript is a general-purpose, object-oriented programming language. It has great usefulness in Web applications because of the browser and document objects that the language supports. Client-side JavaScript interacts with HTML forms. You can use JavaScript to validate user input on the client side, thereby improving the performance of your Web application by reducing the number of requests that flow over the network to the server.
To address various client requirements, Netscape and Microsoft have extended their implementations of JavaScript in version 1.2 by adding new browser objects. Because Netscape's and Microsoft's extensions are different from each other, any script that uses JavaScript 1.2 extensions must determine which browser is being used and select the correct statements to run accordingly.
Versions 3.0 and earlier of both Netscape and Microsoft browsers don't support these new extensions. To run a script on most browsers, use JavaScript 1.1, which contains the core elements of the ECMAScript standard. "JavaScript: The Definitive Guide" (see Resources) is an excellent book on JavaScript, which details the JavaScript objects and methods, listing their origin and JavaScript level.
ECMA, a European standards body, has published a standard (ECMA-262), which is based on JavaScript (from Netscape) and JScript (from Microsoft), called ECMAScript. The ECMAScript standard defines a core set of objects for scripting in Web browsers. JavaScript is a superset of ECMAScript. It is composed of the core ECMAScript objects that run on both Web browsers and servers, as well as a set of unique client-specific and server-specific objects. The core objects include array, date, math, number, and string. On the client side, there are document, form, frame, and window objects. These core objects enable the manipulation of HTML documents (checking form fields, submitting forms, and creating dynamic pages) and the manipulation of the browser (directing the browser to load other HTML pages, display messages, and so on). See Resources for more information about ECMAScript.
JSPs and servlets
You can develop interaction controller and page construction logic using either Java servlets or Java Server Pages (JSP) technology. Both of these implementation mechanisms have significant advantages over using CGI-BIN or Web server plugins. You will need to decide whether to use JSPs or servlets or both in your Web application.
JSPs can contain all the HTML tags that Web authors are familiar with. A JSP may contain fragments of Java code that encapsulate the logic that generates the content for the page. These code fragments may call JavaBeans to access reusable components and back-end data. To learn more about JSPs, see Resources.
Servlets are small Java programs that run on the Web server. They interact with the servlet engine running on the Web server through HTTP requests and responses. JSPs are compiled into servlets before being executed on the Web server. To learn more about servlets, see Resources.
The interaction controller part of a Web application, which is primarily concerned with processing the HTTP request and invoking the correct business or UI logic, often lends itself to implementation as a servlet. This is especially true in cases where one interaction controller processes several types of user interactions. If your design dictates one interaction controller per type of user interaction, JSPs are a better fit. For example, login would be handled by login.jsp, interaction1 by interaction1.jsp, interaction2 by interaction2.jsp and logoff by logoff.jsp.
JSPs were designed to simplify the process of creating pages by separating Web presentation from Web content. In the page construction logic of a Web application, the response sent to the client is often a combination of template data and dynamically-generated data. In this situation, it is much easier to work with JSPs than to do everything with servlets.
Command beans
Command beans provide a standard way to invoke a business logic request using a single round-trip message. A command bean is a JavaBean that encapsulates a single request to a target server (that is, the server where the command is to be executed). The target server can be the same JVM as the client or a separate JVM.
Command beans allow for a clean separation of User Interface (UI) and business logic. The Web application parts (that is, interaction controller and UI logic) can vary independently from the command bean's implementation.
The steps in a command bean's execution are:
- The JSP/servlet instantiates the command bean and sets the command bean's input properties.
- The JSP/servlet calls the perform method on the command bean.
- The perform method, if successful, returns a copy of the command bean with its output properties set to the results of the underlying business logic task.
- Control flows to the JSP/servlet, which is now free to query the output properties of the command bean.
JDBC and SQLJ
The business logic in a command bean accesses information in a database for the topology 1 scenario. JDBC is a Java API for database-independent connectivity. It provides a straightforward way to map SQL types to Java types. With JDBC you can connect to your relational databases, and create and execute dynamic SQL statements in Java. JDBC drivers are RDBMS specific, provided by the DBMS vendor. Given common schemas between two databases, an application can be switched between them by changing the JDBC driver name and URL. A common practice is to place the JDBC driver name and URL information in a property or configuration file.
SQLJ provides a simplified syntax for JDBC that allows you to write SQL-like statements directly in your Java source code. The SQLJ preprocessor generates static SQL providing better performance than dynamic SQL. SQLJ will also generate iterator Java classes. These iterators allow you to navigate query results using a simple "get next" protocol.
Resources
-
Flanagan, David. JavaScript: The Definitive Guide, Third Edition. O'Reilly & Associates, Inc., 1998.
- The ECMAScript Language Specification contains the latest ECMAScript version information.
- To learn more about JSPs, visit http://www.javasoft.com/products/jsp/.
- To learn more about servlets, visit http://www.javasoft.com/products/servlet/.