本文介绍了在Compojure POST请求中缺少表单参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在下面的Compojure示例中获取表单参数时遇到问题:
(ns hello-world
(:use compojure.core,ring.adapter.jetty)
(:require [compojure.route:as route]))
(defn view-form []
(str< html>< head>< / head>< body>
< form method = \post\>
type = \text\name = \title\/>
< input type = \submit\/>
/ form>< / body>< / html>))
(defroutes main-routes
(GET/[]Hello World)
GET/ new[](view-form))
(POST/ new{params:params}(prnparams:params))
(route / not-found ))
(run-jetty main-routes {:port 8088})
提交表单时,输出总是
params:{}
p>
,我不知道为什么title参数不在params地图中。
我使用Compojure 0.6.2。
解决方案您是否考虑过这个:
源:
我尝试过使用我当前的设置它工作。我包括以下:
require [compojure.handler:as handler]
和(handler / api routes)
/ p>I'm having problems getting the form parameters in the following Compojure example:
(ns hello-world (:use compojure.core, ring.adapter.jetty) (:require [compojure.route :as route])) (defn view-form [] (str "<html><head></head><body>" "<form method=\"post\">" "Title <input type=\"text\" name=\"title\"/>" "<input type=\"submit\"/>" "</form></body></html>")) (defroutes main-routes (GET "/" [] "Hello World") (GET "/new" [] (view-form)) (POST "/new" {params :params} (prn "params:" params)) (route/not-found "Not Found")) (run-jetty main-routes {:port 8088})
When submitting the form the output is always
params: {}
and I can't figure out why the title parameter is not in the params map.
I'm using Compojure 0.6.2.
解决方案Have you taken into account this:
Source: https://github.com/weavejester/compojure
I tried your example with my current setup and it worked. I have included the following:
require [compojure.handler :as handler]
and(handler/api routes)
.这篇关于在Compojure POST请求中缺少表单参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!