Servlet GroupHW Problem Set
You are to use the
GroupHW Tool to cooperatively
write
- an html page providing links to scheme servlets illustrating various concepts
- several scheme servlets illustrating those concepts
For references you can use the class notes or the class text.
or anything at the http://jscheme.sourceforge.net site
that is useful.
First write a couple of specific servlets as specified below:
-
For example, illustrate the "let*" instruction by writing
a servlet that prompts the user for three sides (a,b,c) of a triangle
and the computes the area using the formula
Area = sqrt((s-a)(s-b)(s-c)s)
where s = (a+b+c)/2
To do this you should use the "let*" expression:
(let* (
(s (/ (+ a b c) 2))
(area (sqrt (* (- s a) (- s b) (- s c) s)))
)
{......[area].....}
- loading several pages into one servlet using case:
write a servlet which stores all pages for a short talk in one
servlet. The particular page to show is specified by a servlet parameter:
;; multipage.servlet
(servlet (page)
(case page
(("a") { ... first page ... with link to link to multipage.servlet?page=b ...})
(("b") { ... second page with lins to multipage.servlet?page=m and others...})
...
))
Write two or three servlets for each of the following concepts.
- (if TEST THEN ELSE)
- (case ....)
- (cond (TEST1 THEN1) (TEST2 THEN2) ... (TESTK THENK) (else ELSE))
- counters (read-from-file ...) (write-to-file ...)
- logs (append-to-file ...) (read-string-from-file ...)
More complex examples:
- A Chatting Servlet.
For example, you could write a simple "conversation" servlet. That would
have the user enter a sentence in a textfield and then would respond to the
sentence by looking for keywords. The test to see if a string S contains the keyword "you"
is
(>= (.indexOf S "you") 0)
where "(.indexOf S "you")" returns the position of the first occurence of "you" in the
string S, and returns -1 if "you" does not appear in S. If you want you can
define a procedure for testing if a sentence contains any of a list of keywords:
(define (contains S L)
(cond ((null? L) #f)
((= -1 (.indexOf S (first L))) (contains S (rest L)))
(else #t)))
which you can then use as
(cond ((contains S '("sad" "mad" "tired")) {Are you often depressed?})