首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么我的Common Lisp Web程序不能执行

为什么我的Common Lisp Web程序不能执行
EN

Stack Overflow用户
提问于 2012-04-13 17:05:31
回答 1查看 295关注 0票数 2
代码语言:javascript
复制
; 一些辅助函数
(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:

代码语言: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>  

当我访问http://localhost:4444/hello时总是报告500个错误,我怀疑是模板路径,我的操作系统是windows,不知道如何将这个path.web.lisp与下面的index.tmpl写在同一个目录下

EN

回答 1

Stack Overflow用户

发布于 2012-04-13 23:54:00

一个显而易见的问题是“你评估过start-web了吗?”答案可能是“是”,但请注意,为了让您的服务器监听适当的端口,您确实需要调用start。如果您看到Hunchentoot错误页面,这不是问题所在。

fill-and-print-template是如何定义的?如果它需要绝对路径名,您可能需要执行(merge-pathnames "index.tmpl"),而不是传递相对路径。

一般来说,有几件事可以让lisp web开发变得更容易。

  • 考虑defining yourself a package。这将允许您有选择地导入符号,而不是为每个外部符号加上其源包的前缀。它还可以让你使用quicklisp加载你自己的项目,而不是定义你自己的easily.
  • consider。它可以让你轻松地安装和加载外部库(如果你指定的库已经安装好了,asdf:load-op就可以使用ql:quickload了),
  • 看看cl-who,我发现它比HTML模板要友好得多,因为你正在使用hunchentoot:easy-acceptordefine-easy-handler来定义你的页面(这是一点语法糖,让你定义一个处理程序函数,同时将适当的调度程序推送到*dispatch-table*)
  • when调试Hunchentoot应用程序上,为了更好地调试information.

,它对(setf hunchentoot:*catch-errors-p* nil) (或(setf hunchentoot:*show-lisp-errors-p* t),取决于您的喜好)很有帮助

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

https://stackoverflow.com/questions/10138067

复制
相关文章

相似问题

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