在没有请求的情况下使用GroovyPagesTemplateEngine? [英] Using GroovyPagesTemplateEngine without a request?
问题描述
我试图评估没有真正的http请求的GSP文件。我试过这个:
pre $ 字符串compileGsp(文件输入){
def text =''
尝试{
text = groovyPagesTemplateEngine.createTemplate(input).make()。toString()
}
catch(Exception e){
StackTraceUtils.sanitize(e).printStackTrace )
}
返回文本
}
但是这会抛出一个异常并产生这个异常:
java.lang.IllegalStateException:找不到线程绑定请求:是
你引用实际Web请求之外的请求属性
或处理原始接收线程之外的请求?如果
实际上在web请求中运行,并且仍然收到此
消息,那么您的代码可能在
之外运行DispatcherServlet / DispatcherPortlet:在这种情况下,请使用
RequestContextListener或RequestContextFilter以揭露当前的
请求。
如何在没有请求的情况下评估GSP?如果我使用 SimpleTemplateEngine
,我可以获得一些功能,但是我失去了所有的taglibs,其中包括request-void标记,如< g:each>
我猜你可以模拟网络请求。此发布 a>可能就是你要找的。 p> I'm trying to evaluate a GSP file without a real http request. I'm trying this: but this throws an exception and yields this: java.lang.IllegalStateException: No thread-bound request found: Are
you referring to request attributes outside of an actual web request,
or processing a request outside of the originally receiving thread? If
you are actually operating within a web request and still receive this
message, your code is probably running outside of
DispatcherServlet/DispatcherPortlet: In this case, use
RequestContextListener or RequestContextFilter to expose the current
request. How can I evaluate GSPs without a request? If I use I guess you can mock the web request. This posting is probably what you are looking for. 这篇关于在没有请求的情况下使用GroovyPagesTemplateEngine?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!String compileGsp(File input) {
def text = ''
try{
text = groovyPagesTemplateEngine.createTemplate(input).make().toString()
}
catch( Exception e ){
StackTraceUtils.sanitize(e).printStackTrace()
}
return text
}
SimpleTemplateEngine
, I get some functionality, but I lose all of the taglibs, which include request-void tags like <g:each>