0

不是真正的 CL 也不是 Web 编程专家,所以我可能遗漏了一些非常明显的东西:我尝试在 page-1 中设置会话值并在 page-2 中获取结果。但是,第 2 页中没有显示任何内容...

(ql:quickload "cl-who")
(ql:quickload "hunchentoot")

(defpackage :sessmin
  (:use :cl :cl-who :hunchentoot))

(in-package :sessmin)

(defun start-server (port)
  (start (make-instance 'easy-acceptor :port port)))

(setf (html-mode) :html5)

(define-easy-handler (page1 :uri "/page1") ()
  (start-session)
  (setf (session-value :sv) "testvalue")
  (with-html-output-to-string
      (*standard-output* nil :prologue t :indent t)
    (:html :lang "en"
       (:head 
        (:meta :charset "utf-8")
        (:title "page1"))
       (:body 
         (:p "Session Page 1")
         (:p "Go to next page" (:a :href "page2" "here"))))))

(define-easy-handler (page2 :uri "/page2") ()
  (with-html-output-to-string
      (*standard-output* nil :prologue t :indent t)
    (:html :lang "en"
       (:head 
        (:meta :charset "utf-8")
        (:title "page2"))
       (:body 
         (:p "Session Page 2")
         (:p "Session Page 2, value:" (session-value :sv))))))

(start-server 8080)

编辑:在我的第一个版本中得到“(”错误,但更正后仍然无法正常工作......

4

2 回答 2

2

不是 Hunchentoot 专家,但我认为您忘记关闭了:head

于 2014-03-23T22:00:55.033 回答
2

您的问题不是未设置会话值,而是您的 cl-who 格式。

(:p "Session Page 2, value:" (session-value :sv))

不会打印会话值;的返回值session-value被简单地忽略。

;; try this:
(:p "Session Page 2, value:" (str (session-value :sv)))
;; or, if you need to html-escape the value,
(:p "Session Page 2, value:" (esc (session-value :sv)))
于 2014-03-24T11:01:33.203 回答