95-702 Organizational Communication and Distributed Object Technologies
January 2009
Homework 1 Due: Friday, May 29 11:59:59 PM
========== ================================
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 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.
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
:
:
Good Documentation 4 Points
Works Properly 29 Points
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
:
:
Good Documentation 4 Points
Works Properly 29 Points
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.
Good Documentation 4 Points
Works Properly 25 Points
Screenshots provided 3 Points