[plt-scheme] Requests in plt-web-server

From: Jens Axel Soegaard (jensaxel at soegaard.net)
Date: Thu Feb 21 12:12:51 EST 2008

Justin Paston-Cooper wrote:
> Hello. I've recently been developing an article-writing website with 
> plt-web-server, and I've come across a problem with url queries. My code 
> for the page is:
> 
> (module post
>   mzscheme
>  
>   (require (lib "servlet.ss" "web-server"))
>  
>   (provide start interface-version timeout)
>  
>   (define interface-version 'v1)
>   (define timeout +inf.0)
>  
>   (define (start initial-request)
>     (send/finish
>      `(html
>        (body (p (format "~a" (request-bindings initial-request))))))))
> 
> When I go to http://localhost:8080/servlets/post.ss?x=2 , all I get is:
> 
> ~a&initial-request;
> 
> . This is just a test to see if the bindings environment exists. All I 
> really want, is the value of x. Is there anything that I am doing wrong 
> here? Thank you.

Here is a nice trick. Instead of sending debug output to the browser,
launch the web-server from within DrScheme, and send debug info
to standard out.

One way to start the web-server from DrScheme is the found below.

/Jens Axel


;;; launch.ss

; INSTRUCTIONS
;   This file launches a web-server serving a local
;   version of "INSERT APP NAME HERE".
;   Open this file in DrScheme
;   and hit "Run". Then open the printed link in a
;   web-browser near you.

; NOTES
;;   You can change the port number used, but
;;   editing "servlets/config.scm".

(require (lib "web-server.ss" "web-server")
          (lib "web-config-unit.ss" "web-server")
          (lib "config.ss" "planet")
          (lib "etc.ss")
          ; "servlets/private/config.scm"
          )

;;; WEB-SERVER CONFIGURATION

(define config-sexp
   `(; (port ,port)
     (port ,8080)
     (max-waiting 40)
     (initial-connection-timeout 30)
     (default-host-table
       (host-table
        (default-indices "index.html" "index.htm")
        (log-format parenthesized-default)
        (messages
         (servlet-message "servlet-error.html")
         (authentication-message "forbidden.html")
         (servlets-refreshed "servlet-refresh.html")
         (passwords-refreshed "passwords-refresh.html")
         (file-not-found-message "not-found.html")
         (protocol-message "protocol-error.html")
         (collect-garbage "collect-garbage.html"))
        (timeouts
         (default-servlet-timeout 30)
         (password-connection-timeout 300)
         (servlet-connection-timeout 86400)
         (file-per-byte-connection-timeout 1/20)
         (file-base-connection-timeout 30))
        (paths
         (configuration-root "conf")
         (host-root     ,(this-expression-source-directory))
         (file-root     "htdocs")
         (servlet-root  ".")
         (mime-types "mime.types")
         (password-authentication "passwords"))))
     (virtual-host-table)))


; start the web-server, and store a shutdown function
(define shutdown
   (serve/web-config@
     (configuration-table-sexpr->web-config@ config-sexp)))

(display
   (format
    "Start here: http://localhost:~a/servlets/post.scm?a=foo\n\n" port))

(display "Press enter to shutdown.\n")
(read-line)
(shutdown)



;;; post.scm
(module post
   mzscheme

   (require (lib "servlet.ss" "web-server"))

   (provide start interface-version timeout)

   (define interface-version 'v1)
   (define timeout +inf.0)

   (define (start initial-request)
     (print-struct #t)
     (display initial-request)
     (newline)
     (display (request-bindings initial-request))
     (newline)
     (send/finish
      `(html
        (body "POST PAGE")))))




Posted on the users mailing list.