MSc-IT Study Material
June 2010 Edition

Computer Science Department, University of Cape Town

Chapter 19. Web-Application Development

Table of Contents

Examples of Web applications
Blogs
Wikis
Sakai
Digital Libraries
Getting and running Tomcat
Creating a simple Web page
What do Servlets do?
Request Methods
The structure of a Web application
Your first Web application
Handling user input
Cookies and session tracking
Problems with cookies
Response status
The Servlet packages and classes
javax.servlet
javax.servlet.http
Servlet Life-cycle

Web applications are computer applications that the user does not run directly on their own computer, but rather accesses through a Web browser. The GUI is provided by the Web browser (usually as some form of HTML), and all of the application's processing is done either on the browser with JavaScript, on the Web server itself, or on both. This means that Web application development is, in essence, the development of network-based applications, including server-side (i.e., on the Web server) and client-side (i.e., on the Web browser) programming. This module has so far specifically dealt with client-side development, including HTML and JavaScript, but this chapter deals with server-side development.

There are many ways to programme a Web server, including such commonly used technology as PHP and ASP.net. The traditional method of doing so is to use the Common Gateway Interface (CGI), which is a language agnostic interface for adding programmability to Web servers. It allows CGI programmes to be written in any language, and these programmes are executed by the Web server whenever a resource which they supply is requested by a Web browser.

This chapter will introduce you to the equivalent Java solution: Java Servlets. This will allow you to make use of the knowledge that you've gained in the programming module, rather than having to learn a new language.

Servlets are Java objects which are run on a Servlet aware Web server. Each Servlet object is mapped to particular URLs on the server. Instead of simply returning a Web document when a request for an URL is made, the server instead uses the Servlet mapped to the URL to handle the request. The Servlet is free to deal with the request however it feels it should – it can communicate with databases, read or write to the file system, and create arbitrary response data to be returned to the Web browser. Typically, however, this response data is HTML, which the browser than displays for the user.

While Servlets makes use of your Java knowledge, they also have another advantage: because they are designed to replace a portion of a Web server's functionality, they will also give you insight into how a Web server deals with a request for a Web page, more so than many other Web application frameworks. This is always useful knowledge to have, no matter what Web framework you will use in the future.

To begin, you will need access to a Web server able to run Servlets. You can use any such server that you have access to, but these notes will make use of Apache Tomcat, and all of the examples will reflect this. Tomcat is freely available, and brief installation instructions are given later.

Examples of Web applications

The Web has grown to make use of a large number of Web applications. Typical examples that you may have come across include Web-based e-mail clients, online shopping sites, blogs, wiki-wiki, and so on. Visit the sites below to see what kind of functionality they provide:

Blogs

A Web log (or blog) is often described as an online diary, but they have developed into websites that may contain commentary on events and media (such as reviews), original work (such as fiction, or comics), or contain various other media besides text, with video now becoming fairly common. As such, the main feature of blogging software is that it allows the blog's author to regularly and easily add content to it, and this content is typically displayed in chronological order (much like a diary), usually from most recent to least recent. Blogs also provide some functionality to the reader, such as the ability to search through the various entries, or to leave comments for the author and other readers. Blogs can also be written by more than one person, and the software will usually keep track of which author has written which entry.

To Do

Visit a blog service provider such as WordPress, LiveJournal or BlogSpot, and read about the service. Sign up for an account if you are interested to see how such software works.

Wikis

A wiki is a content management system that allows people to view, add or modify the content that it contains. Unlike a blog, which always has a specific person or group of people acting as an author, a wiki usually lets anyone edit the content, and can be described as a collaborative content creation effort by all of its users. Here are some of the common features:

Prior registration to use the service is not typically necessary. This is meant to encourage everyone to contribute, although it does mean that vandalism can more easily occur.

The editing process is often simple, and requires no review procedure prior to publication. In other words, changes are immediately made available to everyone. Again, this is to encourage high levels of contribution.

A wiki system may keep track of the changes made to the content, allowing the users to see the individual changes and when they were made. It also makes it easy to revert content back to an older version if necessary.

One of the main advantages of a wiki is that the knowledge and content that it contains is community-based. This might not mean that the content is more accurate, just more representative of its users' views. A good wiki page should contain a wide variety of views, and as such censorship is frowned upon in many wiki sites. Another advantage is that the system allows for information to be kept up to date with minimal maintenance by any one group of people.

To Do

Visit a wiki site such as Wikipedia, a wiki-based encyclopaedia. Search for a topic and examine the page. Look closely at the discussion, edit and history tabs (on top of each page). Visit an entry on the subject that you might be an expert in. Can you see if there is anything missing? Find out how you could contribute. You could also visit the 'Help' ulink url read about different aspects of the site, such as the standards that people contributing to the site must adhere to.

Sakai

Sakai is an online educational course management system. It allows for managing course resources (notes, exercises, answers etc.), supplies forums, chat rooms, surveys, electronic hand-in facilities, schedulers and calendars, among various other features. The system allows both teachers and students to make use of it, offering them each features appropriate to the different roles that they play. At the University of Cape, our Sakai instance is called Vula, and all students have access to it.

To do

Visit the Vula site if you have not been regularly visiting. Do you think that such a facility has been useful to you? How could it be improved?

Digital Libraries

A digital library, like its real-world counterpart, is a collection of books and reference materials, albeit with the exception that the content is electronic and usually provided over a network. An example of a digital library is Project Gutenberg, a collection of freely available books no longer under copyright protection.

Digital libraries have a number of advantages of traditional libraries, including increased capacity, lower costs and easier accessibility. A digital library can contain large volumes of information that compared to the amount of physical space that it requires. It can also be cheaper to operate one as it requires less maintenance and staff costs, and being available over a network means that it can be used to by people all over the world if the library is made available over the Internet.

However, there are also some disadvantages. For example, there are concerns that copyright issues are hampering the effectiveness of digital libraries, while the sheer volume of information has caused the traditional techniques of finding information to become inefficient. Additionally, many people find it difficult to read long documents on a computer screen, and so they are often printed out, costing money and wasting paper.

To Do

Visit a digital library such as Project Gutenberg. Find a book that you're interested in reading and see if you can download it. Read the library's conditions of use. What do you think of Project Gutenberg? Would you make use of it regularly?