我正在使用Maven作为我的依赖管理器在IntelliJ中使用基于Compojure的Clojure Web应用程序.它基于我在此示例引用的此git存储库中找到的应用程序.当我尝试使用IntelliJ的Tomcat6配置运行应用程序时,每次引用Servlet异常时都会失败:
javax.servlet.ServletException: Wrapper cannot find servlet class tracker.core or a class it depends on
Run Code Online (Sandbox Code Playgroud)
另外,查看web.xml,IntelliJ无法识别servlet类(tracker.core突出显示).
这个应用程序最初是作为客户的概念证明而构建的,由我最近离开公司的同事编写.在过去的两天里,除了在这个项目上工作之外,我个人对clojure没有任何经验.使用Leiningen环服务器,我可以成功地让应用程序在jetty中运行.使用leiningen ring uberwar,由此产生的战争成功地部署并运行在tomcat中.
原始文件结构如下所示:
/tracker-webapp
/classes
/lib
/resources
/src
/tracker
/core.clj (and other *.clj files)
/test
project.clj
Run Code Online (Sandbox Code Playgroud)
新的mavenized文件结构现在反映了前面提到的git repo中的示例:
/tracker-webapp
/src
/main
/clojure
/tracker
/core.clj (and other *.clj files)
/webapp
/WEB-INF
/web.xml
/pom.xml
Run Code Online (Sandbox Code Playgroud)
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<display-name>Simple Clojure WebApp</display-name>
<servlet>
<servlet-name>myservlet</servlet-name>
<servlet-class>tracker.core</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>myservlet</servlet-name>
<url-pattern>/*</url-pattern> …Run Code Online (Sandbox Code Playgroud) 我在以下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\">"
"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})
Run Code Online (Sandbox Code Playgroud)
提交表单时,输出始终是
params: {}
Run Code Online (Sandbox Code Playgroud)
我无法弄清楚为什么title参数不在params地图中.
我正在使用Compojure 0.6.2.
使用ring(以及lein-ring工具) - 我可以在开发中运行时根据文档提供来自"资源"等的静态文件 - 但是 - 当我通过lien uberwar打包时,我不知道如何制作它在容器中运行时提供这些文件.我在wrap-resource上看到了冲突的文档,或者设置了:resource-path但是似乎都没有.
我在Compojure开发的Clojure中有两个不同的Web应用程序.每个使用defroutes来创建它的处理程序.
如何将两种不同的defroutes定义组合成一个defroute?我想将第一个应用程序的路由重用到第二个应用程序.
我正在使用Clojure/Ring/Compojure-0.4/Enlive堆栈来构建Web应用程序.
是否有在该堆叠函数要么带HTML或HTML编码(即,<a>到<a>),以防止跨站脚本攻击用户提供的字符串?
我希望我的程序输出以下HTML:
<!--[if lt IE 8]><link rel="stylesheet" href="../blueprint/ie.css" type="text/css" media="screen, projection"><![endif]-->
Run Code Online (Sandbox Code Playgroud)
有没有办法用Hiccup输出html评论文字?
我有一个ring + compojure应用程序,我想应用不同的中间件,具体取决于路由是Web应用程序的一部分还是api的一部分(基于json).
我在堆栈溢出和其他论坛上找到了这个问题的一些答案,但这些答案似乎比我一直使用的解决方案更复杂.我想知道我是如何做的,以及我在解决方案中可能缺少的东西是否存在缺陷.我正在做的一个非常简化的版本
(defroutes app-routes
(GET "/" [req] dump-req)
(route/not-found "Not Found"))
(defroutes api-routes
(GET "/api" [req] dump-req))
(def app
(routes (-> api-routes
(wrap-defaults api-defaults))
(-> app-routes
(wrap-defaults site-defaults))))
Run Code Online (Sandbox Code Playgroud)
请注意,中间件比我在此处显示的更多.
我遇到的唯一"限制"是,由于app-routes有未找到的路由,它需要到达最后或者在找到api路由之前触发它.
这似乎比我发现的其他一些解决方案更简单,更灵活,似乎要么使用额外的条件中间件,例如ring.middleware.conditional,或者在我看来是更复杂的路由定义,其中有一个额外的defroutes层并且需要用任何"*"等来定义defroutes.
我怀疑在这里有一些微妙的东西,虽然我的方法似乎有效,但它会导致意外行为或导致某些情况等.
我正在尝试使用一体化解决方案将compojure应用程序与LinkedIn,Facebook,Google和Twitter集成在一起.我知道一些现有的java库,例如scribe-java或spring-social可以提供帮助.但是当他们使用clojure时他们很糟糕.我的目标是否有更多适合他们的解决方案?或者,是否有人可以向我指出如何实现目标的工作样本/教程?
在Clojure/Compojure中,如何将地图转换为URL查询字符串?
{:foo 1 :bar 2 :baz 3}
Run Code Online (Sandbox Code Playgroud)
至
foo=1&bar=2&baz=3
Run Code Online (Sandbox Code Playgroud)
在compojure中有没有任何实用方法呢?
如何最方便地将状态注入环处理程序(不使用全局变量)?
这是一个例子:
(defroutes main-routes
(GET "/api/fu" [] (rest-of-the-app the-state)))
(def app
(-> (handler/api main-routes)))
Run Code Online (Sandbox Code Playgroud)
我想the-state进入compojure处理程序main-routes.状态可能类似于使用以下内容创建的地图:
(defn create-app-state []
{:db (connect-to-db)
:log (create-log)})
Run Code Online (Sandbox Code Playgroud)
在非环形应用程序中,我将在main函数中创建状态,并开始将其作为函数参数注入到应用程序的不同组件中.
在:init不使用全局变量的情况下,可以使用ring 函数完成类似的操作吗?