我显然遗漏了一些显而易见的东西,但是:
(ns session-demo.core
(:gen-class)
(:use compojure.core
ring.middleware.session
[hiccup core page form])
(:require [compojure.route :as route]
[compojure.handler :as handler]))
(defn index-page []
(html5
[:body
(form-to [:get "/status"]
(submit-button "Proceed"))]))
(defn status-page [params]
(html5
[:body
[:p "Session: " (:session params)]
[:p "Params: " params]]))
(defroutes the-routes
(GET "/" [] (index-page))
(GET "/status" {session :session :as params} (status-page params)))
(def app
(-> (handler/site the-routes)
wrap-session))单击“继续”按钮后显示:
Session: {}
Params: {:ssl-client-cert nil, :remote-addr "127.0.0.1", :scheme :http, :query-params {}, :session {}, :form-params {}, :multipart-params {}, :request-method :get, :query-string nil, :route-params {}, :content-type nil, :cookies {"org.cups.sid" {:value "72d6fc6a299669e6332da6eb72964f97"}}, :uri "/status", :server-name "localhost", :params {}, :headers {"accept-encoding" "gzip, deflate", "user-agent" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:28.0) Gecko/20100101 Firefox/28.0", "referer" "http://localhost:3000/", "connection" "keep-alive", "accept-language" "en-US,en;q=0.5", "accept" "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", "host" "localhost:3000", "cookie" "org.cups.sid=72d6fc6a299669e6332da6eb72964f97"}, :content-length nil, :server-port 3000, :character-encoding nil, :body #, :flash nil}我希望有意义的东西被设置在(:会话params).
发布于 2014-04-12 01:55:06
会话开始为空。要在会话中放置一些内容,您需要从处理程序返回一个映射,并且在键:session下面您应该提供更新的会话数据。
可能是这样的:
(defn index-page []
{:body (html5
[:body
(form-to [:get "/status"]
(submit-button "Proceed"))])
:session {:test [1 2 3]}})https://stackoverflow.com/questions/23014199
复制相似问题