Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

13. Let's Create a Web Server! > Building a Dynamic Website

Building a Dynamic Website

To try out our shiny new web server, let’s build a simple site that greets a visitor, using the dirt-simple function hello-request-handler:

(defun hello-request-handler (path header params)
   (if (equal path "greeting")
       (let ((name (assoc 'name params)))
          (if (not name)
              (princ "<html><form>What is your name?<input name='name' />
 </form></html>")
             (format t "<html>Nice to meet you, ˜a!</html>" (cdr name))))
       (princ "Sorry... I don't know that page.")))

This hello-request-handler function supports only a single web page, called greeting. The first step in serving up this greeting page is to see if this page is indeed what the client requested . If not, we print an apology to the user for not finding the specified page . Otherwise, we check the request parameters to see if we know the user’s name. If not, we ask the user to enter a username using a web form . If we do know the user’s name, we greet the visitor enthusiastically.


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free 10-Day Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint