Question

Not really a CL nor a Web programming expert, so may be I'm missing something really obvious: I try to set a session-value in page-1 and fetch the result in page-2. Nothing is displayed in page-2, though...

(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)

EDIT: Got the "("s wrong in my first version, still does not work after correction though...

Était-ce utile?

La solution

Your problem is not that the session value is not set, but in your cl-who format.

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

will not print the session value; the return value of session-value is simply ignored.

;; 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)))

Autres conseils

Not a Hunchentoot expert, but I think you forgot to close :head.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top