Click here for more servlets




;; this servlet takes in four parameters ;; and just uses them to make a simple page ;; containing the four values in a list (servlet (name age favcol zzz) (list name age favcol zzz))


;; demo2 -- getting the values using a form... (servlet (name age) (case name ((#null) {add ?name=NAME&age=AGE to the URL and return} ) (("Tim") {Hi Tim, que pasa?}) (else {Hello [name], you are [age] years old} ) ) )


;; this servlet shows how to write a password protected page (servlet (pw) (case pw ((#null) {<form method="get" action="demo3.servlet"> Password: <input type="password" name="pw"> <br> <input type="submit" value="Go for it"> </form>}) (("diane") {<html> <body> Great! you got it. The answer to the quiz is </body> </html> }) (else {Wrong password! })))


;; this servlet shows how to use values sent to the servlet ;; call it as follows: ;; demo4.servlet?a=3&name=tim&c=23 ;; the other parameters will have the value #null (servlet (a b c name age) {the parameters were a=[a], b=[b], c=[c], your name is [name] you are [age] years old } )


;; here is another example of a servlet that inserts values ;; you give it, into a page (servlet (noun verb adj1 adj2 noun2) {One day the [noun] set out for a walk. It [verb] a [adj1] [noun2] and was [adj2] } )


;; This shows how to use the input, textarea, radio, and checkbox form elements ;; notice the funny way of writing textarea. This is need to have it work ;; correctly with the Umethod.... (servlet (a b c d e) (if (equal? a #null) {<html><body> <form method="get" action="demo6.servlet"> Enter a: <input type="text" name="a"><br> Describe yourself in a paragraph:<br> <text[{}]area name="b" rows=10 cols=50>Write here </text[{}]area><br> How do you vote? <select name="c"> <option value="liberal"> Very liberal</option> <option value="rad"> Radical </option> <option value="cons"> Quite conservative</option> <option value="none"> None of the above</option> </select> <br> Sex: <br> <input type="radio" name="sex" value="M">Male<br> <input type="radio" name="sex" value="F">Female</br> <br> Majors:<br> <ul> <li><input type="checkbox" name="major" value="eng">English </li> <li><input type="checkbox" name="major" value="cosi"> Computer Science</li> <li><input type="checkbox" name="major" value="poli"> Politics</li> </ul> <input type="submit" value="Register!"> </form></body></html> } {You entered [a]<br>[b]<br>[c]<br>[d]<br>[e]} ) )


;; this shows how to fold several web pages into a single servlet (servlet (page) (case page ((#null) {<form method="get" action="demo7.servlet"> <select name="page"> <option>first</option> <option>second</option> <option>preface</option> <option>copyright</option> </select> <input type="submit"> </form>}) (("first") {This is the very first page...}) (("second" "preface") {We haven't written these pages yet}) (("copyright") {Tim Hickey Copyright 2002 All Rights Reserved}) (else {How did you get here??? You must be devious!}) ) )


;; this shows how to send email using a servlet (servlet (name email comment) (case name ((#null) { <form method="post" action="demo8.servlet"> name: <input type="text" name="name"><br> email: <input type="text" name="email"><br> comment:<br> <!-- This is a HACK --> <text[{}]area name="comment" rows=10 cols=50> </text[{}]area> <br> <input type="submit"> </form>}) (else (send-mail request "" ;to email ;from "Someone visited your page" ;subject comment ;message ) (send-mail request email "" "thanks for the comments" {email:[email] and su nombre es [name] and you said=[comment]} ) {Thanks [name] for your comment, it has been sent to the author} ) ; close else ) ; close case ) ; close servlet


;; this illustrates the concept of abstraction ;; It is a way of creating "new tags" (servlet () (define (ptag file title blurb cost) { <table border=5 style="background:yellow;width=90%"> <tr> <td><a href="[file]"> <img src="[file]" width=100> </a> </td> <td><b>[title]</b><br> [blurb] </td> <td> <pre> Cost: [cost] + 5.50 shipping and handling </pre> </td> </tr> </table>} ) ; close define {<html> <body> <h1>Posters for sale</h1> [(ptag "dew.jpg" "Morning Dew" "blah blah blah" "$15.00")] [(ptag "../glasses.jpg" "Wine Glasses" "blah blaaaah" "$10.00")] [(ptag "../lines.jpg" "Play" "blaaaaah blaaaah" "$20.00")] </body> </html> } )