首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >下面的lisp程序不能按预期运行

下面的lisp程序不能按预期运行
EN

Stack Overflow用户
提问于 2012-09-14 23:42:52
回答 1查看 145关注 0票数 0

下面是我的lisp代码,用来完成一个简单的web服务器。

代码语言:javascript
复制
; 一些辅助函数
(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的内容如下:

代码语言:javascript
复制
<!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。

EN

回答 1

Stack Overflow用户

发布于 2012-09-18 05:15:22

您需要使用easy-acceptor而不是acceptor来使用*dispatch-table*机制。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12427818

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档