Java as a Server Side Programming Language

September 17, 2004

Prepared by

Mike Emery

University of Guelph-Humber

Qusay H. Mahmoud

Abstract

This report will evaluate JSP, Servlets, and Perl CGI-scripts as a means for server-based web development. The report compares each on the criteria of language syntax, portability, database connectivity, ease of interface development, performance, and training time required. While both JSP and Perl had strong points in their favour, I ultimately decided to go with Servlets because it was a pure Java solution. Because of the pure Java aspect it would allow me to develop faster, cut down my debugging time, and focus my energy on program design as opposed to fighting with learning the language itself.
Table of Contents

Glossary

Introduction

Choosing Tools for Dynamic Web Development

Solutions

Data Source

Development Language Features

Language Syntax

Portability

Database Connectivity

Ease of Interface Development

Performance

Training Time

Recommendations and Results

Conclusion

References...... 11

Glossary

ASF: Apache Software Foundation

CCS: Computing and Communication Services

HTML: Hyper Text Mark-up Language

IASSIST: International Association for Social Science Information Service and Technology

JNDI: Java Naming and Directory Interface

JSP: Java Server Pages

LDAP: Lightweight Directory Access Protocol

MVC: Model View Controller

Perl: Practical Extraction and Reporting Language

Regex: Regular Expression

Introduction

I worked at the University of Guelph during my summer 2004 co-op placement working in the Computing and Communications Services (CCS) department. The University is one of the larger accredited Universities in Ontario and is located in Guelph, Ontario. This department handles the computer infrastructure of the entire school. This includes ResNet, faculty computers, campus software, and support for a variety of software programs. Each division within the CCS department handles a different logical aspect of the computer infrastructure.

The division I was working with was called ‘Academic Services.’ The primary role of this division is to provide support for graduate students in their Masters’ and Ph.D. studies, which usually involves assistance in statistical analysis. Other functions of the Academic Services division include acquiring licenses for software for use within the University, distributing of software through the school’s online distribution site, and developing systems to make it easier for students to access information

My specific position within Academic Services was that of a Java programmer, with my official title being “Co-op Analyst.” When I was hired my supervisor, Bo Wandschneider, was not sure of the projects I was to do, but had some definite ideas in mind. Other members in my team support statistical software, manage the online software distribution site, negotiate site licences for the University, create statistical modules using flash and Cold Fusion and maintaining servers within the department.

My position was temporary and within the department; a student developer is only brought on whenever there is enough money to afford it and there is sufficient work to justify his or her employment. This usually happens on an annual single semester basis, with no regular full-time programmer there in the interim.
Choosing Tools for Dynamic Web Development

Over the course of my work term several web applications were written, while the development process for each could be taken as a case study, my project developing a web application for IASSIST will be used as the primary example as the experience and conclusions I made while developing the application carried over to my decisions regarding my other projects.

The eventual main project of my work-term was to develop a membership database and website for theInternational Association for Social Science Information Service and Technology (IASSIST). This project was initially supposed to be a one to two week project finishing off a database schema for use by the organization to monitor its membership as well as offer basic financial features.

The program was in the early stages of coding after having a design document drafted by a previous co-op student. Upon analysis of the schema and resulting program it quickly became apparent that the existing solution would not be sufficient allow for a growing list of members, permit the easy expansion of the membership list, and be able to provide all of the required functions specified by the association.

I proposed to my boss that I start the project fresh, using a new database schema, and new coding. He agreed, and I began the process of deciding how to implement the new design.

The website would need to support a variety of functions including member registration, updating of personal information, searching the directory, define access permissions to users and groups, generate reports, and provide basic financial reporting.

All of the information on the background would be generated dynamically on the server using information retrieved from some sort of a back end data storage service. The data storage medium would have to be easy to connect to, simple to interface with, and be able to be administered remotely. This data source must be able to accept multiple remote connections, assign permissions on different sections of information, as well as search, add, edit, and delete information in the data-source.

The program itself must be able to generate HTML content dynamically using the back-end data source. The program must be able to act as an intuitive interface between the user and the data source for performing all operations listed in the previous paragraph in the data source. This program should be modular, and easy to modify and extend in the case further features are required of the program in the future as the association’s needs may change.

Ideally the program should adhere to the MVC design paradigm so that each logical section of the program is separate and can be changed without affecting the other areas of the program.

The program would be hosted on some kind of a web-server, the web-server itself should be chosen based on the data-source used, as well as the development language used. Two options for this would be Jakarta Tomcat (an ASF project), or the Apache Web Server.Both are open source, free, and have significant amounts of documentation available online and in reference textbooks.

The program would also have to be cross platform. My workstation ran Windows Server 2003, while the production server ran UNIX. Finding a solution that would work on both was imperative to ensure proper testing, and allow flexibility in future deployment if necessary.

Solutions

The original draft of the application used JSP as a back end using a limited amount of Java Beans for controller functionality. The JSP and beans interfaced with a MySQL database data-source using MySQL’s supplied Java database driver to connect the program and the database. I decided to evaluate three possible solutions for the final program: JSP, Servlets, and Perl CGI scripts while keeping MySQL as the database server. I did not consider Microsoft’s .NET platform as a viable alternative because the end application would be running on a UNIX server, and currently there is no stable .NET platform available on any operating system other than Microsoft Windows.

Data Source

I decided to stay with MySQL as the data provider for the application. While MySQL has a few features which limit its ability compared to other database servers, its capabilities were sufficient for the application’s needs. I was familiar with it before starting the work term; as well it is free and open source for not-for-profit projects. My division’s system administrator was familiar with MySQL and already had it installed on a UNIX server. Because MySQL is a mostly standard SQL compliant product, the back end database could be switched for a more powerful engine if the need ever arose.

Development Language Features

Language Syntax

JSP is created by inserting an identifier into an HTML document and then inserting the appropriate Java code to perform an operation. JSP Therefore conforms very closely to standard Java syntax, with only slight variations. While Java is an object oriented language JSP is more object based. JSP does not create objects within the JSP page, rather it uses existing objects to perform tasks.

While CGI scripts can be written in any language, Perl has become the most dominant development language over the past few years. Perl is a language designed to parse text, and uses very simplified language syntax to allow for fast development. Perl is easy to understand and simple to code, much of the back-end logic is taken care of for the programmer by the interpreter. Perl is a completely procedural language, it does not support custom objects, and therefore presents quite a shift in thought process to develop compared to my standard Object Oriented approach.

Servlets are a server-side implementation for generating web pages based on a request/response model. Servlets are completely coded in java, meaning they are written just like any other java class would be, except that using a special output stream data can be sent directly to the client’s browser. This stream can be used to send text, HTML, images, video, or any other media format the server wishes.

Because Servlets use pure Java, they can become unwieldy in creating HTML and JavaScript for use on the page. All text must be sent over a stream using a method to be displayed on the browser side.

Portability

Because JSP and Servlets both use Java code, they are completely platform-independent. Both JSP and Servlet code adheres completely to Java’s “write once, run anywhere” ideal, and lend themselves to being developed on a machine running a different operating system than the target server, as is the case with my current setup.

Perl also has a degree of cross-platform ability, because Perl is interpreted, its list of available platforms is only limited by which ones have an interpreter written. As it stands both Windows and UNIX have Perl interpreters available.

Database Connectivity

All three possible languages support some means of database connectivity using external libraries and plug-ins. JSP and Servlets would require a driver to access the data source, while Perl has a vast variety of plug-ins which allows it to connect to virtually any data source imaginable.

Ease of Interface Development

JSP is Java code inserted into an html document using special tags, making the design of the page very easy. This would allow the page to be developed using an HTML editor such as Dream weaver and then going in using a text editor to add the JSP code. This greatly simplifies the design process for the html portion of the web page. Another advantage of JSP is that it uses standard Java code. Because of this it has access to all of Java’s libraries, and can interface with custom Java classes.

With Servlets information must be sent over a stream to be displayed on the browser side. This can make debugging the HTML and JavaScript difficult and time consuming.

Since all the html code is contained in a string and often within a method call it can be hard to debug the html. I would have to look at the html in the generated page and then when a bug was found, adjust it in on the server side Servlet code.

Perl is a simple to use, powerful language designed primary for use in parsing text. This lends itself very well to HTML documents, and therefore makes it a common choice for web developers. Also Perl based CGI scripts have been in existence for a very long time; due to its longevity there are a great deal of very comprehensive pre-made scripts, tutorials, and resources available on the internet. The great breath and depth of Perl resources would greatly assist me in developing dynamically generated html pages, as well as possibly allow me to do things far beyond my current comfort level with the language.

Performance

Once a Servlet has been loaded, it stays loaded for others to use, and is done so on the first request for the page. In operations that involve frequent access, this greatly improves performance because the start-up bottleneck is removed for all but the first transaction. Each subsequent request is dispatched to a lightweight Java thread, which further improves performance by being more efficient on memory. By staying persistent in memory, Servlets allow for the reuse of common objects just as Database access objects.

JSP code is parsed by the server and converted into a Servlet. Consequently JSP shares almost all performance characteristics with Servlets, except that they carry a slightly higher initial start-up cost. Each subsequent access of the page is approximately equal to that of a Servlet performing the same operation.

Perl CGIscripts each run in a unique memory space, spawn a unique process on the system, and die after each use. In web environment where requests can come in very high volumes this can present a very significant performance hit under heavy load. Trying to do aperformance boosting technique such as connection pooling in Perl is difficult because of the short lifespan of each process.

Training Time

While JSP does use Java code, certain programming methodologies differ slightly from the standard Java language, as well as additional effort is required to properly set up a MySQL connection using JSP. There would be time loss while I familiarized myself with JSP and played around with making simple JSP pages.

Because Servlets are entirely Java there is not need to learn a different language or different syntax. Another bonus for java is that is it easier on the server. A Servlet class is loaded once on the first request for the page, and a lightweight Java thread is dispatched to deal with the specific request. The Servlet class stays in memory and spawns threads to deal with incoming connections. This makes Servlets relatively light on server resources and makes them very well suited to repeated small operations, which is common in a web environment.

Perl would require the greatest investment of my time to do properly. I have very little Perl programming knowledge, and much of what would be required of me for the project is far beyond what I am used to. Significant time would have to be put into making sample and proof of concept Programs, as well as increasing my debug time for programs.

Recommendations and Results

From the aforementioned data for each solution I decided to go with a Servlet-based solution. While it is not a perfect match for the project, it allowed me to quickly develop the application without the need to do research or practice. It also allowed me to debug the program with a greater degree of competence and confidence than either JSP or Perl would have allowed me to. My suggestion of using an entirely Servlet based solution was approved by my supervisor and I went ahead with development.

Because I chose to go with Servlets with a MySQL back end, Jakarta Tomcat would was chosen as the application server. Configuring Tomcat to use Servlets is a relatively simple affair, and because it supports both Windows and UNIX environments it would allow me to do testing on my workstation, and deploy the application to the UNIX server with absolutely no changes in configuration. The experience of migrating my application from Windows to Unix matched the “write once, run anywhere” ideal Java tries to ascribe to. There were only minor issues encountered because of how the UNIX version of Tomcat handles relative paths differently than its Windows counterpart.

Conclusion

Using the combination of Servlets, a Tomcat Server, and MySQL I was able to create three web-based applications over the course of the semester. The lessons in learned in the design and implementation of the IASSIST project carried over into the development of my two other Web based applications I developed in the semester. Each program met he requirements of my supervisor, and received very positive feedback from him.

I felt these projects greatly contributed to my knowledge of Java, and the projectsboosted my comfort level working with a variety of open source libraries from the Apache Software Foundation’s Jakarta project. This past semester has greatly improved my coding ability, while also raising my awareness of what can be done with the Java programming language.

I have left the department with several applications that will be used for years to come internally, and I feel that I have supplied them with tools that will both simplify repetitive tasks, and reduce the amount of time taken to complete these tasks.
References

JavaServer Pages Technology - JavaServer Pages Comparing Methods for Server-

Side Dynamic Content White Paper [online article]. Sun Microsystems. Accessed 7 May 2004. Available on Internet

JavaServer Pages Technology - White Paper. Sun Microsystems. Accessed 7 May

2004. Available on Internet

Java Servlet API Whitepaper [online article]. Sun Microsystems. Accessed 12

September 2004. Available on Internet

Vawter,Chad;Roman, Ed. J2EE vs Microsoft .NET [online article]. Sun Microsystems,

2001. Accessed 9 May 2004. Available on Internet:

Yank, Kevin. Which Server-Side Lanugage is Right for You? [online article].

SitePoint.com. Accessed 15 May 2004. Available on Internet