Last active
December 25, 2015 11:29
-
-
Save z8888q/6969523 to your computer and use it in GitHub Desktop.
hunchentoot示例,上级目录是web-demo,参见《Windows上搭建hunchentoot开发环境》http://zhan.renren.com/mobileapp?gid=3602888498043591987
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; 一些辅助函数 | |
(require :asdf) | |
(defun loadlib (mod) | |
(asdf:oos 'asdf:load-op mod)) | |
(defun reload () | |
(load "web-demo/web.lisp" :external-format :utf-8)) | |
(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*) | |
;定义模板 | |
(defvar *template* (html-template:create-template-printer #p"web-demo/index.tmpl" | |
:element-type 'character | |
:external-format :utf-8 | |
:force t ;; for debugging | |
)) | |
; 页面控制器函数 | |
(defun hello () | |
(setf (hunchentoot:content-type*) "text/html; charset=utf-8") | |
(with-output-to-string (stream) | |
(html-template:fill-and-print-template | |
*template* | |
(list :name "Lisp程序员") | |
:stream stream))) | |
; 启动服务器 | |
(defun start-web (&optional (port 4444)) | |
(hunchentoot:start (make-instance 'hunchentoot:easy-acceptor :port port))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment