0

以下は、単純なWebサーバーを完成させるための私のlispコードです。

; 一些辅助函数
(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开发实例&lt;/h1>
    hi, <!-- TMPL_VAR name -->
  </body>
</html>

Webを起動すると、localhost:4444 / helloにアクセスできませんが、問題がどこにあるかを特定できません。私はインターネットを検索しました、何人かの人々はそれが道のために私のものであると言いました。しかし、私のコードにはそれに関連するものはないと思います。誰かが来て理由を教えてくれることを願っています。私はubuntu12.10を使用しました。

4

1 に答える 1

2

このメカニズムを使用するには、 のeasy-acceptor代わりにを使用する必要があります。acceptor*dispatch-table*

于 2012-09-17T21:15:22.180 に答える