以下lisp程序无法按预期工作

时间:2012-09-14 15:42:52

标签: web lisp

followwing是我的lisp代码,用于编写简单的Web服务器。

; 一些辅助函数
(require :asdf)
(defun loadlib (mod)
  (asdf:oos 'asdf:load-op mod))

(defun reload ()
  (load "web.lisp"))

; 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"/home/chonglinsun/Learn/cl/lib/web/index.tmpl"
     (list :name "Lisp程序员")
     :stream stream)))
; 启动服务器
(defun start-web (&optional (port 4444))
  (hunchentoot:start (make-instance 'hunchentoot:acceptor :port port)))

(defun restart-web ()
  (progn
    (reload)
    (start-web)))

index.tmpl的内容如下:

<!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>

当我启动web时,我无法访问localhost:4444 / hello,但我无法确定 问题是。我搜索了互联网,有人说是因为我的 路径。但我不认为我的代码中有与之相关的内容。希望会有 有人来告诉我为什么。我使用的是ubuntu 12.10。

1 个答案:

答案 0 :(得分:2)

您需要使用easy-acceptor代替acceptor来使用*dispatch-table*机制。