95-702 Organizational Communication and Distributed Object Technologies
August 28, 2009
Homework 1 Due: Friday, September 11, 11:59:59 PM
========== ======================================
This project has two objectives:
First, the student is introduced to GlassFish. GlassFish
is an open source application server that implements the
JEE 5 specification. This tool is used throughout
the course. The Netbeans integrated development
environment is introduced and is used to build
source code and interact with GlassFish.
Second, the student builds his or her first distributed
systems. The student builds three small web
applications using Java Server Pages and servlets.
The project is demonstrated in class and serves as
a jumping off point to discuss important characteristics
of distributed systems including security, protocols and
interoperability.
In each part, documentation is required. The software that
you write (HTML files, Java files and so on) must contain
comments that describe what each significant piece of code
is intended to accomplish. Points will be deducted if code
is not well documented.
For each of the three exercises below, submit a documented
servlet and an index.jsp page. The documentation will
include your name, a description of each piece of code
and well-chosen variable names. In addition, you must submit
screenshots that demonstrate your programs running.
A complete project will include a short paper (one or
two pages in length). The paper will clearly and
accurately explain the functional characteristics of
the product in relation to the non-functional
characteristics, demonstrating a nuanced comprehension
of course content and explaining the technical aspects
in relation to potential real-world applications.
For this project, the non-functional characteristics
that need to be addressed in your paper include security, protocol
layering and interoperability.
1. Write an index.jsp page that requests a user's name and
provides a submit button. When the submit button is pressed
a servlet is executed. The servlet sends 400 hello messages
back to the browser. Each hello message appears on its own
line and contains the user's name. For example, if the user
enters Richard and hits the submit button, the output will
look as follows:
Hello Richard
Hello Richard
:
:
2. A user can trick this servlet so that it behaves in an unintended
manner. For example, a user might enter HTML code into the input
field. If the input field contains the string "Amy" then
Amy's name will be echoed back to the browser and displayed in
italics. Write code in the servlet that prevents any use of
anlgle brackets in the user input. Note: a complete answer
for question 2 does not count for question 1. Question 1 must
be completed separately.
The way that you will solve this problem is to use the
contains method of the String class. If a left or right
bracket ("<" or ">") appears in the input replace the input
string with the value "illegal characters in input". Send this
string back to the browser.
For example, if the user enters Richard and hits the submit
button, the output will look as follows:
Hello illegal characters in input
Hello illegal characters in input
:
:
3. Write a simple web application that allows a user
to perform one of three operations on two, possibly
very large, integers. The operations will include
addition and multiplication as well as an operation
to determine if the two integers are relatively prime.
A JSP page will present three input fields to
the user. The first two will be used to collect the two
integers. The third will be used to collect the operation
type. The only operations supported will be "add", "multiply",
and "relativelyPrime".
A submit button will be provided and when it is hit
a servlet will be visited. The servlet will use the
BigInteger class to perform the conversions from strings
and the appropriate computation. The servlet will return
the result to the browser marked up in HTML. You need
to validate both integers and the operation. In the case
of invalid input return an error message to the browser
but don't crash the server.
The BigInteger class has multiply and add methods that
will be used by the first two operations. For the operation
that determines if the two integers are relatively
prime use the gcd() method of the BigInteger class. If
the greatest common divisor of the two integers is one
then the two integers are relatively prime.