4.8. PROCESSING NUMBERS USING SERVLETS
55
((0 2 4 6 8) "even digit"))
Next we give an example of a servlet that handles many parameters:
;multiEcho.servlet
(servlet (color name age)
{
multiEcho

Hi [name], so you are [age] years old!

}
)
If this servlet is accessed by visiting the  multiEcho.servlet  URL with the
following parameter string:
?name=Tim&age=46&color=lightgreen
Then the browser will return a lightgreen page with an h1 heading containing
the text
Hi Tim, so you are 46 years old!
Note that the order in which the parameters appear in the URL or in the
parameter list of the servlet does not matter.
4.8
Processing numbers using servlets
Let us now revisit and extend some of the first servlets we considered above. For
example, lets generalize the hypotenuse servlet to handle any triangle provided
we enter the lengths of the two other sides.
One way to write this servlet is the following:
; hypotenuse.servlet
(servlet (a b)
(case (a)
((#null) {Enter data by adding "?a=3&b=4" to the URL})
(else {The right triangle with sides of length [a] and [b],
has a hypotenuse of length
[(sqrt (+ (* a a) (* b b)))]})))
The servlet parameters a and b must be numbers or else the servlet will generate
an error! We will discuss methods for dealing with user input errors in a later
section on  error checking . For now, we assume that the user will follow
instructions and enter numbers when they are expected.




  

Home

About Services Network Support FAQ Order Contact
 

Tomcat Web Hosting

Our partners:Jsp Web Hosting Unlimited Web Hosting Cheapest Web Hosting  Java Web Hosting Web Templates Best Web Templates PHP Mysql Web Hosting Interland Web Hosting Cheap Web Hosting PHP Web Hosting Tomcat Web Hosting Quality Web Hosting Best Web Hosting  Mac Web Hosting 

Lunarwebhost.net  Business web hosting division of Vision Web Hosting Inc. All rights reserved