Simple 32-Bit Adder in JSP/Servlet

illinoiseggoΛογισμικό & κατασκευή λογ/κού

28 Οκτ 2013 (πριν από 3 χρόνια και 10 μήνες)

79 εμφανίσεις

Simple
32
-
Bit
Adder in
JSP/Servlet

Overview

Wri te
a JSP/Servl et

web appl i cati on that adds two
32
-
bit signed integer

numbers. The web appl i cati ons wi l l
consi st of
one JSP page (
index.jsp
) and one Servl et (
adder
). The JSP page i nvokes the adder servl et
usi ng the GET
method.


Technical
Specification

For
the
i ndex.jsp

page you

wi l l need 3 control s: 2 text boxes, and 1 button

(as shown by the fi gure above)
. The two
text boxes wi l l be the area you i nput the numbers

that

you want to sum.
These control s sh
oul d be embedded i n
an HTML form that i nvokes the adder servl et usi ng the GET method.


Required
Control
s

(Important!!)

The
ID

and NAME
of the
fol l owi ng
control s shoul d be
set
exactly
as shown i n the fol l owi ng tabl e.

Required Control

ID
and NAME
(Case
Sensitive)

Text Box 1

txtBox1

Text Box 2

txtBox2

Button “Add”

btnAdd


The 景l l owi ng i s a sampl e code sni ppet 景r decl ari ng these control s:


<form action=”adder” method=”GET”>





<input type=”submit” value=”add” name=”btnAdd” id=”btnAdd” />

</form>


Grading Criteria

Correctness

Thi s web appl i cati on must, fi rst and foremost, work correctl y! If you add two numbers, you shoul d get the correct
answer. The appl i cati on must work correctl y for both posi ti ve and negati ve numbers.

Some sampl e test cases to

consi der:



1 + 1 = 2



1 + 0 = 1



1 + (
-
1) = 0



-
1 + 1 =
0



-
1 + (
-
1) =
-
2



0 + 0 = 0



0 + (
-
1) =
-
1

Overflow Handling

Si nce we are not deal i ng wi th an arbi trary
-
preci si on math l i brary, we are l i mi ted i n the si ze of a number. Si nce we
are usi ng si gned i ntegers,
we are l i mi ted to the range
-
2147483648 to 2147483647. If we take the web appl i cation
and try to add 2147483647 and 1, we wi l l get
-
2147483648. Thi s i s i ncorrect and must be detected. In the case
that thi s happens (or any overfl ow at al l ), we must si mpl
y output “
Exception: Arithmetic Overflow! The input and
the expected result should be within
-
2^31 to 2^31
-
1
” as the resul t.

Input Validation

Thi s web appl i cati on must not onl y work correctl y, but must be robust as wel l. For thi s, you must take care to
ensure certai n test cases work correctl y. For exampl e, you need to make sure that your appl i cation won’t crash, or
won’t di spl ay somethi ng unpredi ctabl e i f you enter somethi ng other than a number. For thi s, you wi l l need some
sort of i nput val i dati on.
I
f anythi ng other than a number i s put i nto any of the text boxes, “
Number conversion
exception. Please enter an integer number into textbox
” shoul d be di spl ayed on the resul t page
.


Security

Whenever your appl i cation di scovers that user tri es to embed
JavaScri pt sni ppet i n i nput, i t shoul d i ssue a warni ng
to the user: “
Warning: potential XSS attack
"
.

Thi s rul e shoul d overri de

the excepti on handi ng for Input Val i dati on
,
whenever appl i cabl e
.

The breakdown of the gradi ng cri teri a i s l i sted i n the fol l owi ng

tabl e.

Requirements

Points

Required Controls

20

Correctness

60

Robustness (overfl ow,
i nput val i dation, securi ty)

20

Total

100


Note that you have to make sure that your appl i cati on passes al l the tests on requi red
control s;

otherwi se none of
the other test cases woul d pass.