Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/clojure/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Clojure 如何在环初始化函数中获取ServletContext_Clojure_Glassfish_Ring - Fatal编程技术网

Clojure 如何在环初始化函数中获取ServletContext

Clojure 如何在环初始化函数中获取ServletContext,clojure,glassfish,ring,Clojure,Glassfish,Ring,我正在使用Clojure+Ring构建一个运行在GlassFish3上的web应用程序。 如何访问环init函数中的ServletContext变量?请求映射中提供了ServletContext(如果有)。我发现查看:context、:servlet context和:servlet context path的值很有用。下面是一个用于确定路径的小型环形中间件: (def ^:dynamic *app-context* nil) (defn wrap-context [handler] (fn

我正在使用Clojure+Ring构建一个运行在GlassFish3上的web应用程序。
如何访问环
init
函数中的
ServletContext
变量?

请求映射中提供了ServletContext(如果有)。我发现查看
:context、:servlet context
:servlet context path
的值很有用。下面是一个用于确定路径的小型环形中间件:

(def ^:dynamic *app-context* nil)

(defn wrap-context [handler]
 (fn [request]
  (when-let [context (:context request)]
    (logging/debug (str "Request with context " context)))
  (when-let [pathdebug (:path-debug request)]
    (logging/debug (str "Request with path-debug " pathdebug)))
  (when-let [servlet-context (:servlet-context request)]
    (logging/debug (str "Request with servlet-context " servlet-context)))
  (when-let [servlet-context-path (:servlet-context-path request)]
    (logging/debug (str "Request with servlet-context-path " servlet-context-path)))
  (binding [*app-context* (str (:context request) "/")]
     (logging/debug (str "Using appcontext " *app-context*))
     (-> request
         handler))))

(defn url-in-context [url]
    (str *app-context* url))

到目前为止你试过什么?请阅读。不幸的是,
init
函数无权访问
request
参数。我看到您正在确定路径,但实际上并没有在上下文中调用url。是否应该从包装上下文调用上下文中的url(即,如果你真的希望你的应用程序无论在哪里都能透明地工作)?否,
url-in-context
将用于应用程序中,例如在视图模型中构建链接。