Assignment 1: Servlets and Web Containers

fortunabrontideInternet et le développement Web

13 nov. 2013 (il y a 4 années et 8 mois)

132 vue(s)

CSCI 5895: Advanced Java Programming for E
-
Commerce


Assignment 1: Servlets and Web Containers


Due Sept. 24


Introduction

You are to implement a simple “tuition calculator” servlet (based somewhat on YSU’s
current undergraduate tuition) called
TuitionServ
let
. Students will enter
information about credits, etc., into a client
-
side web page (which I will provide), and
your servlet will generate a response that outlines the total tuition associated with that
information. This tuition will be based on a number

of constants which will be read in
from a
<servlet>

tag (which I will also provide) on a
web.xml

page.


Client
-
side Web Page

The client
-
side web page is available at the course web site:




It has a number of different types of inputs, including text, ch
eckboxes, radio buttons, and
lists. Note that the user is allowed to choose multiple options from the list (for example,
both “Room and Board” and “Parking Permit”.


You will need to examine the source code in order to determine the
name

(and the
associat
ed
value

for the radio buttons and the list options), since you will need to use
them in your servlet to acquire the corresponding values entered by the user:


<FORM METHOD=POST ACTION="http://localhost:8080/examples/servlet/Tuition">


Credits: <INPUT TYP
E=TEXT NAME="
credits
" SIZE=5>

<BR>

<BR><INPUT TYPE=CHECKBOX NAME="
engineering
"> Joint Engineering Program

<BR>

<BR><INPUT TYPE=RADIO NAME="
surcharge
" VALUE="
resident
" CHECKED> Resident

<BR><INPUT TYPE=RADIO NAME="
surcharge
" VALUE="
nonresident
"> Non
-
residen
t

<BR>

<BR>

<SELECT NAME="
additional
" SIZE=3 MULTIPLE>


<OPTION VALUE="
room
">Room and Board


<OPTION VALUE="
meals
">Meal Plan


<OPTION VALUE="
parking
">Parking Permit

</SELECT>

<BR>

<BR>

<INPUT TYPE=SUBMIT VALUE="COMPUTE TUITION">

</FORM>


Also note that

the form uses the
post

method, and that it calls a servlet called
Tuition

in
the
examples

application directory on the local host. You can modify this if you want to
put the servlet in a directory that you create (this won’t affect my ability to grade you
r
servlet). Nothing else about this form should be modified!


Servlet Logic

The tuition is to be computed based on the following rules:



If the
number of credits

is
12 or greater
, then the student is
full time

with a base
tuition of
$2172
.



If the
number of
credits

is
11 or less
, then the student is
part time

with a base
tuition of
$181 per credit hour
.



If the student is
part time

and the
Joint Engineering Program

is checked, then the
base tuition is
$225 per credit hour

instead.


If the
non
-
resident
radio bu
tton is checked, then a
surcharge

is added. Specifically:



If the student is
full time
, then the surcharge is
$1151
.



If the student is
full time
, then the surcharge is
$96 per credit hour
.


If any
options are chosen from the list
, corresponding charges are
added to the total
tuition:



Room and Board

is an additional
$3050
.



Meal Plan

is and additional
$999
.



Parking Permit
is an additional
$68
.


Servlet Output

Your servlet is to generate a simple web page that lists the individual charges and the
total tuition.

A couple of examples:







Your servlet should also
validate the number of credits
. Specifically, the number of
credits must be a
number

greater than 0
.


If the number of credits is not legal, an appropriate error message should be generated
instead
. For example:









Initial Parameters in the Web Container

In order to make it easy for non
-
programmers to modify the constants used above (that is,
the tuitions, surcharges, additional costs, etc.), they should be stored in the
web.xml

file
as
ini
tial prameters
.


In order to do this, you can copy and paste the following into either the existing
web.xml

file in the
examples

application directory (before the last
</web
-
app>

tag,
or into a new
web.xml

file if you create your own directory:


<servlet>


<servlet
-
name>Tuition</servlet
-
name>


<servlet
-
class>TuitionServlet</servlet
-
class>


<init
-
param>


<param
-
name>PartTimeFee</param
-
name>


<param
-
value>181</param
-
value>


</init
-
param>


<init
-
param>


<param
-
name>FullTimeFee</param
-
name>


<
param
-
value>2172</param
-
value>


</init
-
param>


<init
-
param>


<param
-
name>JointEngineeringProgram</param
-
name>


<param
-
value>225</param
-
value>


</init
-
param>


<init
-
param>


<param
-
name>PartTimeSurcharge</param
-
name>


<param
-
value>96</param
-
v
alue>


</init
-
param>


<init
-
param>


<param
-
name>FullTimeSurcharge</param
-
name>


<param
-
value>1151</param
-
value>


</init
-
param>


<init
-
param>


<param
-
name>RoomAndBoard</param
-
name>


<param
-
value>3050</param
-
value>


</init
-
param>


<init
-
par
am>


<param
-
name>MealPlan</param
-
name>


<param
-
value>999</param
-
value>


</init
-
param>


<init
-
param>


<param
-
name>ParkingPermit</param
-
name>


<param
-
value>68</param
-
value>


</init
-
param>

</servlet>


You will then need to read in these parame
ters (using the names used above such as
PartTimeFee
) in the
init

method of your servlet. Note that you are not to change
these names or values!


Also note that this maps the name
Tuition

to the servlet with name
TuitionServlet
. This means that your servle
t class must be called
TuitionServlet
.


Other Notes

As with any other program you write, your servlet must be
well documented
.


Extra credit may be given for servlets that are particularly well designed, or have
particularly nice output.


What to Turn In

Y
ou are to turn in a
diskette

with your
TuitionServlet.java

file, along with a
hardcopy

of the file. I will grade your servlet by plugging it into my Tomcat server
directory (using my own web page and
web.xml

file).