You don't know how to get started with web development using the PLT Web server.
The
instaweb program takes care of setting up the Web server for most common configurations. The other
WebRecipes and
[the Web server documentation should help answer any questions with the actual programming of servlets.
Instaweb provides a front end to setup the Web server to run a single servlet. Let's say you have a servlet in a file
demo.ss:
(module demo mzscheme
(require (lib "servlet.ss" "web-server"))
(provide interface-version
timeout
start)
(define interface-version 'v1)
(define timeout +inf.0)
(define (start initial-request)
'(html
(head
(title "Demonstration Page"))
(body
(h1 "Demonstration Page")
(p "This is a simple servlet demonstration page"))))
)
To setup the Web server to use this servlet, create another file called, say
run-demo.ss which contains:
(require (planet "instaweb.ss" ("schematics" "instaweb.plt" 1)))
(instaweb "demo.ss" 8765)
Now load
run-demo.ss into
DrScheme (or
MzScheme) and Execute it. You should see output like:
Web server started on port 8765
Visit URL http://localhost:8765/servlets/demo.ss
Type stop to stop the server and exit
Type restart to restart the server
Now visit the URL and check that the servlet is working. That's it!
This is great!
Here is an example of using Instaweb to with a servlet that gets arguments sent to the servlet, along with some embedded javascript (intended to be bookmarked) that allows you to extract select text and metadata (url and title) from an arbitrary page and send it to the servlet.
(module snatcher mzscheme
(require
(lib "servlet.ss" "web-server"))
(provide interface-version timeout start)
(define interface-version 'v1)
(define timeout (* 60 60 24))
(define (start initial-request)
(define binding-list (format "~s"(request-bindings initial-request)))
`(html (head (title "A Test Page"))
(body ([bgcolor "white"])
(p "Query;"
(div ((class="aboutsmall"))
(p "Drag this link: " (a ((href "javascript:location.href='http://127.0.0.1:5678/?v=1;url='+encodeURIComponent(location.href)+';title='+encodeURIComponent(document.title)+';text=\\r'+escape(document.getSelection().replace(/\\s/g,' ').replace(/ {2,}/g,' '))") (title "post to snatcher") (onclick "window.alert('Drag this link to your bookmarks toolbar, or right-click it and choose Bookmark This Link...');return false;") ( class "bookmarklet2")) "post to snatcher") " up to your Bookmarks Toolbar.")
(p ,(string-append "text:" binding-list))
))))))
Instaweb would be called
(require
(lib "url.ss" "net")
(lib "external.ss" "browser") (planet "instaweb.ss" ("schematics" "instaweb.plt" 2 2)))
(instaweb #:servlet-path "snatcher.ss" #:port 5678)
you can then launch the browser with;
(send-url "http://127.0.0.1:5678/?v=1;url=2;title=aaa")
If you want to use instaweb to start the server without the interactive console(that can block your app, you can use;
(run-server 5678 "127.0.0.1" (list #:servlet-path "yourservlet.ss")))
--
StephenDeGabrielle - 15 Jan 2008
--
NoelWelsh - 27 Nov 2006