; 一些輔助函數
(require :asdf)
(defun loadlib (mod)
(asdf:oos 'asdf:load-op mod))
(defun reload()
(load "web.lisp"))
(defun restart-web()
(progn
(reload)
(start-web)))
; load 需要的庫
(loadlib :html-template)
(loadlib :hunchentoot)
; 設置 hunchentoot 編碼
(defvar *utf-8* (flex:make-external-format :utf-8 :eol-style :lf))
(setq hunchentoot:*hunchentoot-default-external-format* *utf-8*)
; 設置url handler 轉發表
(push (hunchentoot:create-prefix-dispatcher "/hello" 'hello) hunchentoot:*dispatch-table*)
; 頁面控制器函數
(defun hello()
(setf (hunchentoot:content-type*) "text/html; charset=utf-8")
(with-output-to-string (stream)
(html-template:fill-and-print-template
#p"index.tmpl"
(list :name "Lisp程序員")
:stream stream)))
; 啓動服務器
(defun start-web (&optional (port 4444))
(hunchentoot:start (make-instance 'hunchentoot:acceptor :port port)))
模板index.tmpl:爲什麼是Common Lisp的Web程序的執行我不能
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Test Lisp Web</title>
</head>
<body>
<h1>Lisp web開發實例</h1>
hi, <!-- TMPL_VAR name -->
</body>
</html>
當我參觀http://localhost:4444/hello 總是報500錯誤,我懷疑是模板路徑, 我的操作系統是windows, 不知道如何在同一個目錄下用index.tmpl寫這個path.web.lisp
謝謝!我的問題真的在於路徑,修改路徑。 – user1076871 2012-04-14 17:54:23