Are you looking to learn web development but don't know where to start? Do you struggle to keep track of all the different languages, frameworks, and tools that are used in web development? Look no further! Our web development notes have got you covered.
Our comprehensive notes cover all the ess...
Southern Alberta Institute of Technology (SAIT
)
Web Programming
CPRG 213A
All documents for this subject (12)
Seller
Follow
arshshops24
Content preview
Web-Application Development
Chapter 17. Web-Application
Development
Table of Contents
Objectives .............................................................................................................................................. 1
17.1 Introduction .............................................................................................................................. 1
17.2 Examples of Web applications................................................................................................ 2
17.2.1 Blogs .............................................................................................................................. 2
17.2.2 Wikis .............................................................................................................................. 2
17.2.3 Sakai .............................................................................................................................. 3
17.2.4 Digital Libraries ............................................................................................................. 3
17.3 What do Servlets do? ............................................................................................................... 3
17.3.1 Request Methods ........................................................................................................... 4
17.4 The structure of a Web application .......................................................................................... 4
17.5 Your first Web application ....................................................................................................... 5
17.6 Handling user input .................................................................................................................. 6
17.7 Cookies and session tracking ................................................................................................... 9
17.8 Problems with cookies ........................................................................................................... 15
17.9 Response status ...................................................................................................................... 17
17.10 The Servlet packages and classes ........................................................................................... 19
17.10.1 javax.servlet ............................................................................................................... 19
17.10.2 javax.servlet.http ........................................................................................................ 20
17.11 Servlet Life-cycle ................................................................................................................... 20
Objectives
At the end of this unit you will be able to:
• Understand some web applications;
• What servlets do;
• Write a web application using servlet packages and classes.
17.1 Introduction
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
1
, Web-Application Development
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. Instructions on how to install and use Tomcat were given in Chapter 2.
17.2 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:
• Amazon [http://www.amazon.com]
• Kalahari.net [http://www.kalahari.net]
• E-Bay [http://www.ebay.com]
• GMail [http://www.gmail.com]
• Wikipedia [http://www.wikipedia.org]
• Open Street Map [http://www.openstreetmap.org]
•
17.2.1 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.
17.2.2 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
2
, Web-Application Development
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.
17.2.3 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?
17.2.4 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 [http://www.gutenberg.org], 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?
17.3 What do Servlets do?
3
The benefits of buying summaries with Stuvia:
Guaranteed quality through customer reviews
Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.
Quick and easy check-out
You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.
Focus on what matters
Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!
Frequently asked questions
What do I get when I buy this document?
You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.
Satisfaction guarantee: how does it work?
Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.
Who am I buying these notes from?
Stuvia is a marketplace, so you are not buying this document from us, but from seller arshshops24. Stuvia facilitates payment to the seller.
Will I be stuck with a subscription?
No, you only buy these notes for $20.49. You're not tied to anything after your purchase.