Common lisp 如何将Web应用程序连接到Hunchentoot

Common lisp 如何将Web应用程序连接到Hunchentoot,common-lisp,hunchentoot,Common Lisp,Hunchentoot,我正在编写一个需要hunchentoot web服务器的web应用程序。我几乎不了解hunchentoot,也不了解任何web服务器,我想知道我用Common Lisp编写的应用程序如何为web客户端提供页面。我看到了一些很好的例子(例如,用于Web的Lisp),特别是Hunchentoot页面上列出的例子。你知道我在哪里可以找到更多这样的例子吗? 谢谢 我想知道我用CommonLisp编写的应用程序如何为web客户端提供页面 Hunchentoot提供其*分派表*中的所有内容,该表只是分派处理

我正在编写一个需要hunchentoot web服务器的web应用程序。我几乎不了解hunchentoot,也不了解任何web服务器,我想知道我用Common Lisp编写的应用程序如何为web客户端提供页面。我看到了一些很好的例子(例如,用于Web的Lisp),特别是Hunchentoot页面上列出的例子。你知道我在哪里可以找到更多这样的例子吗? 谢谢

我想知道我用CommonLisp编写的应用程序如何为web客户端提供页面

Hunchentoot提供其
*分派表*
中的所有内容,该表只是分派处理程序的列表

最简单的方法是提供一个静态文件。一个典型的例子是CSS文件:

(push (create-static-file-dispatcher-and-handler "/example.css"
                                                 "example.css")
      *dispatch-table*)
对于web应用程序,您很可能希望动态创建web页面。您可以通过定义一个以字符串形式返回页面的函数(例如,使用CL-WHO),然后为此函数创建一个处理程序:

(defun foo ()
  (with-html-output-to-string ; ...
  ))

(push (create-prefix-dispatcher "/foo.html" 'foo)
      *dispatch-table*)
您可以通过宏消除大量样板文件,顺便说一下:

(defmacro standard-page ((title) &body body) `(with-html-output-to-string (*standard-output* nil :prologue t :indent t) (:html :xmlns "http://www.w3.org/1999/xhtml" :xml\:lang "de" :lang "de" (:head (:meta :http-equiv "Content-Type" :content "text/html;charset=utf-8") (:title ,title) (:link :type "text/css" :rel "stylesheet" :href "/example.css")) (:body ,@body)))) (defmacro defpage (name (title) &body body) `(progn (defmethod ,name () (standard-page (,title) ,@body)) (push (create-prefix-dispatcher ,(format nil "/~(~a~).html" name) ',name) *dispatch-table*))) (defmacro标准页((标题)和正文) `(html输出为字符串(*标准输出*nil:prologue t:indent t) (:html:xmlns)http://www.w3.org/1999/xhtml" :xml \:lang“de” :lang“de” (:头) (:meta:http等价于“内容类型” :content“text/html;charset=utf-8”) (:头衔,头衔) (:link:键入“text/css” :rel“样式表” :href“/example.css”)) (:正文) (@body))) (定义宏定义页(名称(标题)和正文) `(项目 (defmethod,name() (标准页(,标题) (@body)) (推送(创建前缀调度器,(格式为nil/(~a~).html“name)”,名称) *调度表*))
您找到的示例应该足以让您开始学习,如果遇到问题,请阅读手册,然后提出具体问题。

定义轻松处理程序
在全局变量中注册您正在自动定义的处理程序,当HTTP请求到达时,该处理程序将被检查(变量名为
*easy handler*
)。因此它将自动处理。是否要使用与教程中定义的不同形式的处理程序


我认为大象发行版中有一个使用Hunchentoot的例子(作为CommonLisp的持久对象数据库)

你发现示例中缺少什么?如果你不说,你很可能会得到更多缺少相同内容的示例链接。好吧,我想更清楚地了解如何将应用程序的其余代码连接到hunchentoot;应用程序应该如何与hunchentoot对话。链接已失效,新链接万岁:我无法提供static html通过使用html文件的
create static file dispatcher and handler
链接到css文件。我该怎么办?@FSC:看来你有一个新问题。请将其作为主题发布,并提供必要的上下文。