subchen / jetbrick-template-2x Goto Github PK
View Code? Open in Web Editor NEWTemplate Engine for Java
Home Page: http://subchen.github.io/jetbrick-template/
License: Other
Template Engine for Java
Home Page: http://subchen.github.io/jetbrick-template/
License: Other
#tag profile("production")
如果在生产环境下,这段文本将被显示。
#end
#tag profile("!production")
如果不是生产环境,这段文本将被显示。
#end
@subchen 我先记录在issue里,有时间我来做。
建议再添加一个与JFinalModelGetterResolver相似的 JFinalRecordGetterResolver, JFinal ActiveRecordPlugin 下除了 Model 这个类承载数据以外,还有 Record 这个类也承载数据,而且比较常用,建议添加,感谢支持 jfinal ^_^
在velocity与spring的集成中,
可以通过如下配置来实现:
中设置
页面默认使用 default.vm作为模板,当不需要使用时,在某一个页面加入
当前页面就会使用empty作为默认模板,希望JETX也能有个类似的功能。
我自定义if指令
directive_if : DIRECTIVE_OPEN_IF exp block DIRECTIVE_END
;
exp : IDENTIFIER
| INT
| '<'
| '>'
| IDENTIFIER (exp)*
;
DIRECTIVE_OPEN_IF : '#if' ARG_START;
代码测试时
str = '#if(age > 18) b=#{age} #end‘’
在分词时 将age > 18) b= 作为了exp
报错: age > 18) b=) ' expecting {'<', '>', IDENTIFIER, INT}
不是期望的(age > 18) 作为exp b=#{age} 作为block
究竟怎么匹配?
main.jetx
#for(int x: [0,1,2])
${x}
#end
#include("sub.jetx")
sub.jetx
#for(int x: [0,1,2])
${x}
#end
出现错误
java.lang.IllegalStateException: inconsistent class for variable: for
at jetbrick.template.runtime.ValueStack.setLocal(ValueStack.java:164)
at jetbrick.template.parser.ast.AstDirectiveFor.execute(AstDirectiveFor.java:81)
at jetbrick.template.parser.ast.AstStatementList.execute(AstStatementList.java:202)
at jetbrick.template.parser.ast.AstTemplate.execute(AstTemplate.java:37)
at jetbrick.template.runtime.InterpretContextImpl.doIncludeCall(InterpretContextImpl.java:128)
at jetbrick.template.parser.ast.AstDirectiveInclude.execute(AstDirectiveInclude.java:67)
at jetbrick.template.parser.ast.AstStatementList.execute(AstStatementList.java:202)
at jetbrick.template.parser.ast.AstTemplate.execute(AstTemplate.java:37)
at jetbrick.template.JetTemplateImpl.doInterpret(JetTemplateImpl.java:156)
at jetbrick.template.JetTemplateImpl.render(JetTemplateImpl.java:141)
at jetbrick.template.online.service.TemplateService$1.call(TemplateService.java:28)
at jetbrick.template.online.service.TemplateService$1.call(TemplateService.java:19)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1146)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:679)
配置属性
jetx.trim.directive.comments=true
jetx.trim.directive.whitespaces=true
jetx.trim.leading.whitespaces=true
test.html
<!-- #if(true) -->
xxx
<!-- #end -->
#include('inc.html')
bb
<!-- #include('inc.html') -->
aa
inc.html
INC
**
输出:
xxx
INC
**
bb
<!-- INC
**
-->
aa
问题: include不能正常去注释符,if等指令正常
正常情况下第二个INC不应该注释符的,
如题,在1x版本中有一个热加载配置项目,而2x版本中并没有看到有此配置项,而且在运行中修改模版也无效,需要重启才能生效!
jetbrick不支持前缀prefix吗?
我想要输出的结果是换行的。
String s="【开仓】来自:${user.userID} \n${user.standardSymbol},${user.operationType} ${user.standardLots}\n${user.openPrice}\n${user.openTime}";
JetTemplate template1 = jetEngine.createTemplate(s);
StringWriter writer = new StringWriter();
Map<String, Object> contextMap = new HashMap<String, Object>();
contextMap.put("user", messageTemplate);
template1.render(contextMap, writer);
System.out.println(writer.toString());
直接定义 String s。然后输入是可以换行。 但是吧 String s的从mysql 获取就不换行直接显示的是\n 输出,这是为啥?
System:
Java 8 U 92 64-bit
Windows 10
Jetbrick-template 2.1.2
There seems to be an issue that if you want to load a template it retruns the stacktrace below:
jetbrick.io.resource.ResourceNotFoundException: /templates/hello.jetx
at jetbrick.template.JetTemplateImpl.reload(JetTemplateImpl.java:75)
at jetbrick.template.JetEngineImpl.getTemplate(JetEngineImpl.java:94)
at spark.template.jetbrick.JetbrickTemplateEngine.render(JetbrickTemplateEngine.java:79)
at spark.TemplateViewRouteImpl$1.render(TemplateViewRouteImpl.java:61)
at spark.TemplateViewRouteImpl$1.render(TemplateViewRouteImpl.java:58)
at spark.TemplateViewRouteImpl.render(TemplateViewRouteImpl.java:85)
at spark.http.matching.Routes.execute(Routes.java:62)
at spark.http.matching.MatcherFilter.doFilter(MatcherFilter.java:126)
at spark.embeddedserver.jetty.JettyHandler.doHandle(JettyHandler.java:50)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:189)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:119)
at org.eclipse.jetty.server.Server.handle(Server.java:517)
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:308)
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:242)
at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:261)
at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:95)
at org.eclipse.jetty.io.SelectChannelEndPoint$2.run(SelectChannelEndPoint.java:75)
at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.produceAndRun(ExecuteProduceConsume.java:213)
at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.run(ExecuteProduceConsume.java:147)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:654)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:572)
at java.lang.Thread.run(Thread.java:745)
However going back to 2.1.1 fixes this and there for must be a but in jetbrick-commons as that was the only thing that was updated. Please can you look in to this.
目前输出了很多疑似debug模式的日志
[INFO] Loading template: (source)
[INFO] Loading template: (source)
[INFO] Loading template: (source)
[INFO] Loading template: (source)
[INFO] Loading template: (source)
[INFO] Loading template: (source)
[INFO] Loading template: (source)
[INFO] Loading template: (source)
log4j.properties配置如下
……
log4j.logger.jetx.debug= ERROR
……
也尝试过将 log4j.logger.jetx.debug注释掉,但还是有很多info信息打印出来。。。
AstText 中通过反射获取String.value时,报类型转存错误
# String.java
private final byte[] value;
# AstText.java
(char[]) FIELD_STRING_VALUE.get(text);
几个疑问:
String.toCharArray()
方法即可?这样就没有java版本的问题spring-boot打包为jar,或者war,直接使用java -jar target/ircs-0.0.1-SNAPSHOT.war
运行无法加载模板。eclipse调试时正常
[INFO] cn.com.sinosoft.platform.ircs.Application - Started Application in 23.38 seconds (JVM running for 24.825)
[INFO] cn.com.sinosoft.platform.ircs.Application - Access URLs:
----------------------------------------------------------
Local: http://127.0.0.1:8080
External: http://127.0.0.1:8080
----------------------------------------------------------
[ERROR] org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/].[dispatcherServlet] - Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is jetbrick.io.resource.ResourceNotFoundException: index.html] with root cause
jetbrick.io.resource.ResourceNotFoundException: index.html
at jetbrick.template.JetTemplateImpl.reload(JetTemplateImpl.java:75) ~[jetbrick-template-2.0.9.jar!/:2.0.9]
at jetbrick.template.JetEngineImpl.getTemplate(JetEngineImpl.java:94) ~[jetbrick-template-2.0.9.jar!/:2.0.9]
at jetbrick.template.web.springmvc.JetTemplateView.renderMergedTemplateModel(JetTemplateView.java:36) ~[jetbrick-template-springmvc-2.0.9.jar!/:2.0.9]
at org.springframework.web.servlet.view.AbstractTemplateView.renderMergedOutputModel(AbstractTemplateView.java:167) ~[spring-webmvc-4.1.6.RELEASE.jar!/:4.1.6.RELEASE]
at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:303) ~[spring-webmvc-4.1.6.RELEASE.jar!/:4.1.6.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1244) ~[spring-webmvc-4.1.6.RELEASE.jar!/:4.1.6.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1027) ~[spring-webmvc-4.1.6.RELEASE.jar!/:4.1.6.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:971) ~[spring-webmvc-4.1.6.RELEASE.jar!/:4.1.6.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893) ~[spring-webmvc-4.1.6.RELEASE.jar!/:4.1.6.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966) ~[spring-webmvc-4.1.6.RELEASE.jar!/:4.1.6.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:857) ~[spring-webmvc-4.1.6.RELEASE.jar!/:4.1.6.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:618) ~[tomcat-embed-core-8.0.20.jar!/:8.0.20]
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842) ~[spring-webmvc-4.1.6.RELEASE.jar!/:4.1.6.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:725) ~[tomcat-embed-core-8.0.20.jar!/:8.0.20]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291) ~[tomcat-embed-core-8.0.20.jar!/:8.0.20]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) ~[tomcat-embed-core-8.0.20.jar!/:8.0.20]
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) ~[tomcat-embed-websocket-8.0.20.jar!/:8.0.20]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) ~[tomcat-embed-core-8.0.20.jar!/:8.0.20]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) ~[tomcat-embed-core-8.0.20.jar!/:8.0.20]
at com.codahale.metrics.servlet.AbstractInstrumentedFilter.doFilter(AbstractInstrumentedFilter.java:104) ~[metrics-servlet-3.1.1.jar!/:3.1.1]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) ~[tomcat-embed-core-8.0.20.jar!/:8.0.20]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) ~[tomcat-embed-core-8.0.20.jar!/:8.0.20]
at org.springframework.boot.actuate.autoconfigure.EndpointWebMvcAutoConfiguration$ApplicationContextHeaderFilter.doFilterInternal(EndpointWebMvcAutoConfiguration.java:291) ~[spring-boot-actuator-1.2.3.RELEASE.jar!/:1.2.3.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.1.6.RELEASE.jar!/:4.1.6.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) ~[tomcat-embed-core-8.0.20.jar!/:8.0.20]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) ~[tomcat-embed-core-8.0.20.jar!/:8.0.20]
at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:207) ~[spring-security-web-4.0.0.RELEASE.jar!/:na]
at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:176) ~[spring-security-web-4.0.0.RELEASE.jar!/:na]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) ~[tomcat-embed-core-8.0.20.jar!/:8.0.20]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) ~[tomcat-embed-core-8.0.20.jar!/:8.0.20]
at org.springframework.boot.actuate.trace.WebRequestTraceFilter.doFilterInternal(WebRequestTraceFilter.java:102) ~[spring-boot-actuator-1.2.3.RELEASE.jar!/:1.2.3.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.1.6.RELEASE.jar!/:4.1.6.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) ~[tomcat-embed-core-8.0.20.jar!/:8.0.20]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) ~[tomcat-embed-core-8.0.20.jar!/:8.0.20]
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:85) ~[spring-web-4.1.6.RELEASE.jar!/:4.1.6.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.1.6.RELEASE.jar!/:4.1.6.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) ~[tomcat-embed-core-8.0.20.jar!/:8.0.20]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) ~[tomcat-embed-core-8.0.20.jar!/:8.0.20]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219) ~[tomcat-embed-core-8.0.20.jar!/:8.0.20]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106) [tomcat-embed-core-8.0.20.jar!/:8.0.20]
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501) [tomcat-embed-core-8.0.20.jar!/:8.0.20]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142) [tomcat-embed-core-8.0.20.jar!/:8.0.20]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) [tomcat-embed-core-8.0.20.jar!/:8.0.20]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88) [tomcat-embed-core-8.0.20.jar!/:8.0.20]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:516) [tomcat-embed-core-8.0.20.jar!/:8.0.20]
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1086) [tomcat-embed-core-8.0.20.jar!/:8.0.20]
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:659) [tomcat-embed-core-8.0.20.jar!/:8.0.20]
at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:223) [tomcat-embed-core-8.0.20.jar!/:8.0.20]
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1558) [tomcat-embed-core-8.0.20.jar!/:8.0.20]
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1515) [tomcat-embed-core-8.0.20.jar!/:8.0.20]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [na:1.7.0_51]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [na:1.7.0_51]
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-8.0.20.jar!/:8.0.20]
at java.lang.Thread.run(Thread.java:744) [na:1.7.0_51]
用jetx 怎么能和分reammark 一样实现 页面的静态化呢。
自定义 tag 实现如下:
@JetAnnotations.Tags
public class MyTags {
private static final TimedSizeCache cache = new TimedSizeCache(128);
public static void cache(JetTagContext ctx, String name, int timeout) throws IOException {
Map<String, Object> context = new HashMap<String, Object>();
context.put("userlist", DaoUtils.getUserList());
String templateName = "/users.jetx";
JetTemplate template = ctx.getEngine().getTemplate(templateName);
OutputStream out = new java.io.ByteArrayOutputStream();
template.render(context, out);
String value = out.toString();
System.out.println(value+"\n");
ctx.getWriter().print(value);
out.close();
}
}
报以下错误:
jetbrick.template.runtime.InterpretException: tag invoke error: demo.MyTags#cache()
template: index.jetx: 527,5
-------------------------------------------------------------------------------
525: <div>
526:
527: #tag cache("CACHE-ME-30-MIN", 30*60)
^ -- here
528: 今天天气:
529: #end
-------------------------------------------------------------------------------
] with root cause
java.lang.NullPointerException
at jetbrick.template.runtime.JetTagContext.getWriter(JetTagContext.java:75)
at jetbrick.demo.MyTags.cache(MyTags.java:31)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at jetbrick.bean.MethodInfo.invoke(MethodInfo.java:192)
at jetbrick.template.resolver.tag.TagInvoker.invoke(TagInvoker.java:41)
at jetbrick.template.parser.ast.AstDirectiveTag.doInvoke(AstDirectiveTag.java:70)
at jetbrick.template.parser.ast.AstDirectiveTag.execute(AstDirectiveTag.java:51)
at jetbrick.template.parser.ast.AstStatementList.execute(AstStatementList.java:202)
at jetbrick.template.parser.ast.AstTemplate.execute(AstTemplate.java:37)
at jetbrick.template.JetTemplateImpl.doInterpret(JetTemplateImpl.java:156)
at jetbrick.template.JetTemplateImpl.render(JetTemplateImpl.java:147)
at jetbrick.template.web.springmvc.JetTemplateView.renderMergedTemplateModel(JetTemplateView.java:37)
at org.springframework.web.servlet.view.AbstractTemplateView.renderMergedOutputModel(AbstractTemplateView.java:167)
at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:303)
at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1228)
at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1011)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:955)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:857)
我现在在写一个jdbc动态sql的解析模板
select * from user
#where
#if(username)
and username = ${username}
#end
。。。
#end
在解析where 指令时 writer.append('where')
后面 怎么获得where 指令 Block 的最后结果 以便去掉第一个and
nginx配置https反向代理tomcat,模板WEBROOT变量返回的scheme为http,导致访问失败。
看了一下代码
/* */ private String getWebrootPath()
/* */ {
/* 166 */ StringBuilder sb = new StringBuilder();
/* 167 */ String schema = this.request.getScheme();
/* 168 */ int port = this.request.getServerPort();
/* 169 */ sb.append(schema);
/* 170 */ sb.append("://");
/* 171 */ sb.append(this.request.getServerName());
/* 172 */ if ((((port != 80) || (!("http".equals(schema))))) && (((port != 443) || (!("https".equals(schema)))))) {
/* 173 */ sb.append(':').append(this.request.getServerPort());
/* */ }
/* 175 */ sb.append(this.request.getContextPath());
/* 176 */ return sb.toString();
/* */ }
String schema = this.request.getScheme();这个只能取到当前tomcat的scheme,不能获取到nginx正确的https scheme。
虽然修改tomcat和nginx配置(修改方法如下https://www.cnblogs.com/interdrp/p/4881785.html),能够解决问题,但能否在jetbrick-template-web中增加判断request header中的X-Forwarded-Proto值来取的正确的scheme。
当我使用spring aop时候出现内存溢出错误!关闭aop功能就不会出现此问题。求问如何解决?
java.lang.OutOfMemoryError: PermGen space
java.lang.ClassLoader.defineClass1(Native Method)
java.lang.ClassLoader.defineClass(ClassLoader.java:800)
java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2479)
org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:880)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1294)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1177)
jetbrick.template.JetTemplate.generateJavaSource(JetTemplate.java:175)
jetbrick.template.JetTemplate.compileAndLoadClass(JetTemplate.java:138)
jetbrick.template.JetTemplate.(JetTemplate.java:65)
jetbrick.template.JetEngine$ConcurrentTemplateCache.doGetValue(JetEngine.java:318)
jetbrick.template.JetEngine$ConcurrentTemplateCache.doGetValue(JetEngine.java:314)
jetbrick.template.utils.ConcurrentCache.get(ConcurrentCache.java:44)
jetbrick.template.JetEngine.getTemplate(JetEngine.java:116)
jetbrick.template.web.springmvc.JetTemplateView.renderMergedTemplateModel(JetTemplateView.java:37)
org.springframework.web.servlet.view.AbstractTemplateView.renderMergedOutputModel(AbstractTemplateView.java:167)
org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:266)
org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1225)
org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1012)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:876)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:852)
javax.servlet.http.HttpServlet.service(HttpServlet.java:618)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
The test/bench code is from https://github.com/mbosecke/template-benchmark
All the engines (except Rocker) included here were modified to use a macro.
Here's my local results:
java -jar target/benchmarks.jar -wi 0 -i 1 -f 2 -r 1 -bm ss -bs 100 "(Pebble|Httl|St4|Rocker|Jetx)"
V1
Benchmark Mode Cnt Score Error Units
Httl.benchmark ss 2 0.231 s/op
Jetx.benchmark ss 2 0.053 s/op
Pebble.benchmark ss 2 0.188 s/op
Rocker.benchmark ss 2 0.140 s/op
St4.benchmark ss 2 0.227 s/op
V2
Benchmark Mode Cnt Score Error Units
Httl.benchmark ss 2 0.228 s/op
Jetx.benchmark ss 2 0.174 s/op
Pebble.benchmark ss 2 0.190 s/op
Rocker.benchmark ss 2 0.147 s/op
St4.benchmark ss 2 0.228 s/op
java -jar target/benchmarks.jar -wi 0 -i 1 -f 2 -r 1 "(Pebble|Httl|St4|Rocker|Jetx)"
V1
Httl.benchmark thrpt 2 5483.067 ops/s
Jetx.benchmark thrpt 2 30215.029 ops/s
Pebble.benchmark thrpt 2 8619.356 ops/s
Rocker.benchmark thrpt 2 12937.180 ops/s
St4.benchmark thrpt 2 3127.479 ops/s
V2
Httl.benchmark thrpt 2 5548.510 ops/s
Jetx.benchmark thrpt 2 14575.544 ops/s
Pebble.benchmark thrpt 2 8722.606 ops/s
Rocker.benchmark thrpt 2 13186.748 ops/s
St4.benchmark thrpt 2 3076.100 ops/s
My config for v1 was:
props.setProperty(JetConfig.COMPILE_DEBUG, "false");
props.put(JetConfig.IMPORT_PACKAGES, "com.mitchellbosecke.benchmark.model.*");
props.put(JetConfig.TEMPLATE_LOADER, ClasspathResourceLoader.class.getName());
props.put(JetConfig.TEMPLATE_PATH, "/");
props.put(JetConfig.COMPILE_PATH, "target/jetx");
Is there a similar config for v2 with: props.put(JetConfig.COMPILE_PATH, "target/jetx");
?
I wanted to inspect the generated code before posting here.
The syntax difference from v1 i believe is the macro call ${item_detail(item, for.index)}
#define (List items)
#macro item_detail(Stock item, int count)
<tr class="${count % 2 == 0 ? "even" : "odd"}">
<td>${count}</td>
<td>
<a href="/stocks/${item.symbol}">${item.symbol}</a>
</td>
<td>
<a href="${item.url}">${item.name}</a>
</td>
<td>
<strong>${item.price}</strong>
</td>
#if(item.change < 0.0)
<td class="minus">${item.change}</td>
<td class="minus">${item.ratio}</td>
#else
<td>${item.change}</td>
<td>${item.ratio}</td>
#end
</tr>
#end
<!DOCTYPE html>
<html>
<head>
<title>Stock Prices</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<meta http-equiv="Content-Script-Type" content="text/javascript" />
<link rel="shortcut icon" href="/images/favicon.ico" />
<link rel="stylesheet" type="text/css" href="/css/style.css" media="all" />
<script type="text/javascript" src="/js/util.js"></script>
<style type="text/css">
/*<![CDATA[*/
body {
color: #333333;
line-height: 150%;
}
thead {
font-weight: bold;
background-color: #CCCCCC;
}
.odd {
background-color: #FFCCCC;
}
.even {
background-color: #CCCCFF;
}
.minus {
color: #FF0000;
}
/*]]>*/
</style>
</head>
<body>
<h1>Stock Prices</h1>
<table>
<thead>
<tr>
<th>#</th>
<th>symbol</th>
<th>name</th>
<th>price</th>
<th>change</th>
<th>ratio</th>
</tr>
</thead>
<tbody>
#for (Stock item : items)#call item_detail(item, for.index)#end
</tbody>
</table>
</body>
</html>
All in all, your library is still the fastest when the templates have macros (I tested it against pebble/httl/etc).
如题:
宏 Macro的参数值来自于调用页面的${变量}值,如何传递?
能否支持从数据库加载的加载器JdbcResourceLoader
为何表达式在set中不能解析输出?
例如:#set(String CTX = "${request.contextPath}")
${CTX}输出${request.contextPath},而我要的结果是解析后的值。。
请问有什么办法解决吗?
目前是否支持I18N,支持的话如何配置使用?
Hi! @subchen , we found multiple versions of com.github.subchen:jetbrick-commons:jar exist in com.github.subchen:jetbrick-template-jetbrickmvc:jar:2.1.6. As shown in the following dependency tree, based on "Maven's nearest wins strategy", only the older version 2.0.1 will be loaded, and the newer version 2.1.5 will be shadowed.
However, method <jetbrick.util.JavaKeywordsUtils: boolean isKeyword(java.lang.String)> only included in jetbrick-commons 2.1.5, when your project referencing it, an exeception java.lang.NoClassDefFoundError will be thrown.
Exception in thread "main" java.lang.NoClassDefFoundError: jetbrick/util/JavaKeywordsUtils
at jetbrick.template.parser.AstCodeVisitor.validateIdentifier(AstCodeVisitor.java:838)
at jetbrick.template.parser.AstCodeVisitor.visitDirective_define_expression(AstCodeVisitor.java:216)
at jetbrick.template.web.jetbrickmvc.Test2.main(Test2.java:13)
Caused by: java.lang.ClassNotFoundException: jetbrick.util.JavaKeywordsUtils
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 3 more
com.github.subchen:jetbrick-template-jetbrickmvc:jar:2.1.6
+- com.github.subchen:jetbrick-template-web:jar:2.1.6:compile
| +- com.github.subchen:jetbrick-template:jar:2.1.6:compile
| | +- (com.github.subchen:jetbrick-commons:jar:2.1.5:compile - omitted for conflict with 2.0.1)
| | +- org.antlr:antlr4-runtime:jar:4.7.1:compile
| | - (org.slf4j:slf4j-api:jar:1.7.7:compile - omitted for duplicate)
| - org.slf4j:slf4j-api:jar:1.7.7:compile
+- javax.servlet:javax.servlet-api:jar:3.0.1:provided
- com.github.subchen:jetbrick-webmvc:jar:2.0:compile
+- com.github.subchen:jetbrick-commons:jar:2.0.1:compile
| - (org.slf4j:slf4j-api:jar:1.7.7:compile - omitted for duplicate)
+- com.github.subchen:jetbrick-ioc:jar:2.0.1:compile
| +- (com.github.subchen:jetbrick-commons:jar:2.0.1:compile - omitted for duplicate)
| - (org.slf4j:slf4j-api:jar:1.7.7:compile - omitted for duplicate)
+- com.github.subchen:jetbrick-regex-jdk6:jar:1.0:compile
- (org.slf4j:slf4j-api:jar:1.7.7:compile - omitted for duplicate)
Use jetbrick-commons 2.1.5 in your pom.xml.
The reported dependency issue is detected by an automated test case generation tool.
As some complex branches are difficult to cover, to trigger the execution of missing method, we mutated one of your source file before testing. We forced the conditional statement of branch:
else if (JavaKeywordsUtils.isKeyword(name)) in method validateIndentifier(string, boolean,ParseTree) to be "TRUE". After executing this branch, we then got the above stack trace.
Could please check whether the mutated branch condition is reasonable?
Removing the dependency conflict problem will benefit the software maintenance. ^_^
Thanks again!
Leo
Test case executed with the mutated program:
Test2.txt
Mutated program:
AstCodeVisitor_mutated.txt
Original program:
AstCodeVisitor_original.txt
May I pull a request to fix it?
Thanks.
Regards,
Leo
2015-09-21 14:56:57.372 [http-nio-8080-exec-8] ERROR o.s.boot.context.web.ErrorPageFilter - Forwarding to error page from request [/] due to exception [0]
java.lang.ArrayIndexOutOfBoundsException: 0
at jetbrick.template.Errors.isReflectIllegalArgument(Errors.java:92) ~[jetbrick-template-2.0.10.jar:2.0.10]
at jetbrick.template.parser.ast.AstInvokeField.doInvokeGetter(AstInvokeField.java:92) ~[jetbrick-template-2.0.10.jar:2.0.10]
at jetbrick.template.parser.ast.AstInvokeField.execute(AstInvokeField.java:57) ~[jetbrick-template-2.0.10.jar:2.0.10]
at jetbrick.template.parser.ast.AstValue.execute(AstValue.java:36) ~[jetbrick-template-2.0.10.jar:2.0.10]
at jetbrick.template.parser.ast.AstStatementList.execute(AstStatementList.java:212) ~[jetbrick-template-2.0.10.jar:2.0.10]
at jetbrick.template.parser.ast.AstTemplate.execute(AstTemplate.java:37) ~[jetbrick-template-2.0.10.jar:2.0.10]
at jetbrick.template.runtime.InterpretContextImpl.doIncludeCall(InterpretContextImpl.java:132) ~[jetbrick-template-2.0.10.jar:2.0.10]
at jetbrick.template.parser.ast.AstDirectiveInclude.execute(AstDirectiveInclude.java:67) ~[jetbrick-template-2.0.10.jar:2.0.10]
at jetbrick.template.parser.ast.AstStatementList.execute(AstStatementList.java:212) ~[jetbrick-template-2.0.10.jar:2.0.10]
at jetbrick.template.parser.ast.AstTemplate.execute(AstTemplate.java:37) ~[jetbrick-template-2.0.10.jar:2.0.10]
at jetbrick.template.JetTemplateImpl.doInterpret(JetTemplateImpl.java:160) ~[jetbrick-template-2.0.10.jar:2.0.10]
at jetbrick.template.JetTemplateImpl.render(JetTemplateImpl.java:147) ~[jetbrick-template-2.0.10.jar:2.0.10]
at jetbrick.template.web.springmvc.JetTemplateView.renderMergedTemplateModel(JetTemplateView.java:37) ~[jetbrick-template-springmvc-2.0.10.jar:2.0.10]
at org.springframework.web.servlet.view.AbstractTemplateView.renderMergedOutputModel(AbstractTemplateView.java:167) ~[spring-webmvc-4.2.0.RELEASE.jar:4.2.0.RELEASE]
at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:303) ~[spring-webmvc-4.2.0.RELEASE.jar:4.2.0.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1244) ~[spring-webmvc-4.2.0.RELEASE.jar:4.2.0.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1027) ~[spring-webmvc-4.2.0.RELEASE.jar:4.2.0.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:971) ~[spring-webmvc-4.2.0.RELEASE.jar:4.2.0.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893) ~[spring-webmvc-4.2.0.RELEASE.jar:4.2.0.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970) ~[spring-webmvc-4.2.0.RELEASE.jar:4.2.0.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861) ~[spring-webmvc-4.2.0.RELEASE.jar:4.2.0.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:622) ~[servlet-api.jar:na]
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846) ~[spring-webmvc-4.2.0.RELEASE.jar:4.2.0.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729) ~[servlet-api.jar:na]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291) [catalina.jar:8.0.26]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) [catalina.jar:8.0.26]
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) ~[tomcat-websocket.jar:8.0.26]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) [catalina.jar:8.0.26]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) [catalina.jar:8.0.26]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330) ~[spring-security-web-3.2.7.RELEASE.jar:3.2.7.RELEASE]
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:118) ~[spring-security-web-3.2.7.RELEASE.jar:3.2.7.RELEASE]
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:84) ~[spring-security-web-3.2.7.RELEASE.jar:3.2.7.RELEASE]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) ~[spring-security-web-3.2.7.RELEASE.jar:3.2.7.RELEASE]
at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113) ~[spring-security-web-3.2.7.RELEASE.jar:3.2.7.RELEASE]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) ~[spring-security-web-3.2.7.RELEASE.jar:3.2.7.RELEASE]
at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:103) ~[spring-security-web-3.2.7.RELEASE.jar:3.2.7.RELEASE]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) ~[spring-security-web-3.2.7.RELEASE.jar:3.2.7.RELEASE]
at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113) ~[spring-security-web-3.2.7.RELEASE.jar:3.2.7.RELEASE]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) ~[spring-security-web-3.2.7.RELEASE.jar:3.2.7.RELEASE]
at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:154) ~[spring-security-web-3.2.7.RELEASE.jar:3.2.7.RELEASE]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) ~[spring-security-web-3.2.7.RELEASE.jar:3.2.7.RELEASE]
at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45) ~[spring-security-web-3.2.7.RELEASE.jar:3.2.7.RELEASE]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) ~[spring-security-web-3.2.7.RELEASE.jar:3.2.7.RELEASE]
at org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilter(BasicAuthenticationFilter.java:150) ~[spring-security-web-3.2.7.RELEASE.jar:3.2.7.RELEASE]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) ~[spring-security-web-3.2.7.RELEASE.jar:3.2.7.RELEASE]
at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:199) ~[spring-security-web-3.2.7.RELEASE.jar:3.2.7.RELEASE]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) ~[spring-security-web-3.2.7.RELEASE.jar:3.2.7.RELEASE]
at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:110) ~[spring-security-web-3.2.7.RELEASE.jar:3.2.7.RELEASE]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) ~[spring-security-web-3.2.7.RELEASE.jar:3.2.7.RELEASE]
at org.springframework.security.web.csrf.CsrfFilter.doFilterInternal(CsrfFilter.java:85) ~[spring-security-web-3.2.7.RELEASE.jar:3.2.7.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.2.0.RELEASE.jar:4.2.0.RELEASE]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) ~[spring-security-web-3.2.7.RELEASE.jar:3.2.7.RELEASE]
at org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(HeaderWriterFilter.java:57) ~[spring-security-web-3.2.7.RELEASE.jar:3.2.7.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.2.0.RELEASE.jar:4.2.0.RELEASE]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) ~[spring-security-web-3.2.7.RELEASE.jar:3.2.7.RELEASE]
at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87) ~[spring-security-web-3.2.7.RELEASE.jar:3.2.7.RELEASE]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) ~[spring-security-web-3.2.7.RELEASE.jar:3.2.7.RELEASE]
at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:50) ~[spring-security-web-3.2.7.RELEASE.jar:3.2.7.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.2.0.RELEASE.jar:4.2.0.RELEASE]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) ~[spring-security-web-3.2.7.RELEASE.jar:3.2.7.RELEASE]
at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:192) ~[spring-security-web-3.2.7.RELEASE.jar:3.2.7.RELEASE]
at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160) ~[spring-security-web-3.2.7.RELEASE.jar:3.2.7.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) [catalina.jar:8.0.26]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) [catalina.jar:8.0.26]
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:85) ~[spring-web-4.2.0.RELEASE.jar:4.2.0.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.2.0.RELEASE.jar:4.2.0.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) [catalina.jar:8.0.26]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) [catalina.jar:8.0.26]
at org.springframework.boot.context.web.ErrorPageFilter.doFilter(ErrorPageFilter.java:116) [spring-boot-1.2.5.RELEASE.jar:1.2.5.RELEASE]
at org.springframework.boot.context.web.ErrorPageFilter.access$000(ErrorPageFilter.java:60) [spring-boot-1.2.5.RELEASE.jar:1.2.5.RELEASE]
at org.springframework.boot.context.web.ErrorPageFilter$1.doFilterInternal(ErrorPageFilter.java:91) [spring-boot-1.2.5.RELEASE.jar:1.2.5.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.2.0.RELEASE.jar:4.2.0.RELEASE]
at org.springframework.boot.context.web.ErrorPageFilter.doFilter(ErrorPageFilter.java:109) [spring-boot-1.2.5.RELEASE.jar:1.2.5.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) [catalina.jar:8.0.26]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) [catalina.jar:8.0.26]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219) [catalina.jar:8.0.26]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106) [catalina.jar:8.0.26]
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502) [catalina.jar:8.0.26]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142) [catalina.jar:8.0.26]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) [catalina.jar:8.0.26]
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616) [catalina.jar:8.0.26]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88) [catalina.jar:8.0.26]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518) [catalina.jar:8.0.26]
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091) [tomcat-coyote.jar:8.0.26]
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:673) [tomcat-coyote.jar:8.0.26]
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1526) [tomcat-coyote.jar:8.0.26]
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1482) [tomcat-coyote.jar:8.0.26]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_40]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_40]
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-util.jar:8.0.26]
at java.lang.Thread.run(Thread.java:745) [na:1.8.0_40]
2015-09-21 14:56:58.494 [http-nio-8080-exec-7] ERROR o.s.boot.context.web.ErrorPageFilter - Forwarding to error page from request [/violates/
使用环境如下
JDK11
jetbrick-template-2.1.9
jetbrick-commons-2.1.8.jar
在使用 jetbrick-template-2.1.9
的时候, 引入的 jetbrick-commons-2.1.8.jar
在项目启动的时候, 报如下警告
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by jetbrick.bean.MethodInfo (file:/C:/Users/zaoangod/.m2/repository/com/github/subchen/jetbrick-commons/2.1.8/jetbrick-commons-2.1.8.jar) to method java.lang.Object.finalize()
WARNING: Please consider reporting this to the maintainers of jetbrick.bean.MethodInfo
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
spring-boot 2.0 的ANTLR版本是4.6,每次加载模板会产生警告:
ANTLR Tool version 4.3 used for code generation does not match the current runtime version 4.6ANTLR Runtime version 4.3 used for parser compilation does not match the current runtime version 4.61
[16-11-13 20:57:42:031 CST] 0000012b servlet E com.ibm.ws.webcontainer.servlet.ServletWrapper service Uncaught service() exception thrown by servlet dispatcherServlet: java.lang.IllegalAccessError: sun.reflect.MagicAccessorImpl
at java.lang.ClassLoader.defineClassImpl(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:262)
at jetbrick.bean.asm.AsmClassLoader.defineClass(AsmClassLoader.java:69)
at jetbrick.bean.asm.AsmFactory.generateAccessor(AsmFactory.java:66)
at jetbrick.bean.KlassInfo.getAsmAccessor(KlassInfo.java:493)
at jetbrick.bean.FieldInfo.get(FieldInfo.java:127)
at jetbrick.template.parser.ast.AstText$Jdk6CharArrayEncoder.(AstText.java:276)
at jetbrick.template.parser.ast.AstText.execute(AstText.java:214)
at jetbrick.template.parser.ast.AstStatementList.execute(AstStatementList.java:212)
at jetbrick.template.parser.ast.AstDirectiveIf.execute(AstDirectiveIf.java:43)
at jetbrick.template.parser.ast.AstStatementList.execute(AstStatementList.java:212)
at jetbrick.template.parser.ast.AstTemplate.execute(AstTemplate.java:37)
at jetbrick.template.runtime.InterpretContextImpl.doIncludeCall(InterpretContextImpl.java:132)
at jetbrick.template.parser.ast.AstDirectiveInclude.execute(AstDirectiveInclude.java:67)
at jetbrick.template.parser.ast.AstStatementList.execute(AstStatementList.java:212)
at jetbrick.template.parser.ast.AstTemplate.execute(AstTemplate.java:37)
at jetbrick.template.JetTemplateImpl.doInterpret(JetTemplateImpl.java:160)
at jetbrick.template.JetTemplateImpl.render(JetTemplateImpl.java:141)
是什么原因导致?asm3.1
这样的逻辑连接符会导致 第一个判断条件未能正确判断
`jetbrick.io.resource.ResourceNotFoundException: templates/login.html
at jetbrick.template.JetTemplateImpl.reload(JetTemplateImpl.java:75) ~[jetbrick-template-2.1.2.jar:2.1.2]
at jetbrick.template.JetEngineImpl.getTemplate(JetEngineImpl.java:94) ~[jetbrick-template-2.1.2.jar:2.1.2]
at jetbrick.template.web.springmvc.JetTemplateView.renderMergedTemplateModel(JetTemplateView.java:36) ~[jetbrick-template-springmvc-2.1.2.jar:2.1.2]
at org.springframework.web.servlet.view.AbstractTemplateView.renderMergedOutputModel(AbstractTemplateView.java:167) ~[spring-webmvc-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:303) ~[spring-webmvc-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1257) ~[spring-webmvc-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1037) ~[spring-webmvc-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:980) ~[spring-webmvc-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897) ~[spring-webmvc-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970) ~[spring-webmvc-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861) ~[spring-webmvc-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:622) ~[tomcat-embed-core-8.5.5.jar:8.5.5]
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846) ~[spring-webmvc-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729) ~[tomcat-embed-core-8.5.5.jar:8.5.5]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230) ~[tomcat-embed-core-8.5.5.jar:8.5.5]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) ~[tomcat-embed-core-8.5.5.jar:8.5.5]
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) ~[tomcat-embed-websocket-8.5.5.jar:8.5.5]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192) ~[tomcat-embed-core-8.5.5.jar:8.5.5]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) ~[tomcat-embed-core-8.5.5.jar:8.5.5]
at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99) ~[spring-web-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192) ~[tomcat-embed-core-8.5.5.jar:8.5.5]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) ~[tomcat-embed-core-8.5.5.jar:8.5.5]
at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:89) ~[spring-web-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192) ~[tomcat-embed-core-8.5.5.jar:8.5.5]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) ~[tomcat-embed-core-8.5.5.jar:8.5.5]
at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77) ~[spring-web-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192) ~[tomcat-embed-core-8.5.5.jar:8.5.5]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) ~[tomcat-embed-core-8.5.5.jar:8.5.5]
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197) ~[spring-web-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192) ~[tomcat-embed-core-8.5.5.jar:8.5.5]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) ~[tomcat-embed-core-8.5.5.jar:8.5.5]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198) ~[tomcat-embed-core-8.5.5.jar:8.5.5]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:108) [tomcat-embed-core-8.5.5.jar:8.5.5]
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472) [tomcat-embed-core-8.5.5.jar:8.5.5]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140) [tomcat-embed-core-8.5.5.jar:8.5.5]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) [tomcat-embed-core-8.5.5.jar:8.5.5]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87) [tomcat-embed-core-8.5.5.jar:8.5.5]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:349) [tomcat-embed-core-8.5.5.jar:8.5.5]
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:784) [tomcat-embed-core-8.5.5.jar:8.5.5]
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) [tomcat-embed-core-8.5.5.jar:8.5.5]
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:802) [tomcat-embed-core-8.5.5.jar:8.5.5]
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1410) [tomcat-embed-core-8.5.5.jar:8.5.5]
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-embed-core-8.5.5.jar:8.5.5]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [na:1.7.0_79]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [na:1.7.0_79]
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-8.5.5.jar:8.5.5]
at java.lang.Thread.run(Thread.java:745) [na:1.7.0_79]
`
配置文件:
spring.jetbrick.template.enabled=true spring.jetbrick.template.charset=UTF-8 spring.jetbrick.template.content-type=text/html spring.jetbrick.template.prefix=templates/ spring.jetbrick.template.suffix=.html
请问怎么解决?
错误提示:
`
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Wed Oct 05 08:56:54 CST 2016
There was an unexpected error (type=Internal Server Error, status=500).
templates/login.html
`
控制器内容:
@RequestMapping(value = "/login", method = RequestMethod.GET) public ModelAndView Login(HttpSession session) { ModelAndView result = new ModelAndView("login"); if (session.getAttribute("hasvcode") != null && "true".equalsIgnoreCase(session.getAttribute("hasvcode").toString())) { result.addObject("hasvcode", true); } else { result.addObject("hasvode", false); } return result; }
templates文件夹存在,login.html也存在.. .请问怎么解决?
应用场景,如点击一个菜单,需要从数据库加载子菜单,服务器返回的json需要渲染成指定模板的html,并且把子菜单显示出来。
前端新手,希望不要介意这么低级的问题。谢谢。
jetbrick.io.resource.ResourceNotFoundException: /templates/india_cushion.jetx
at jetbrick.template.JetEngineImpl.getTemplate(JetEngineImpl.java:101)
at controllers.TemplateController.generate_mobile_description(TemplateController.kt:117)
at views.MobileDescription$2$1.invoke(MobileDescription.kt:93)
at views.MobileDescription$2$1.invoke(MobileDescription.kt:22)
at kotlin.concurrent.ThreadsKt$thread$thread$1.run(Thread.kt:18)
使用默认的$loader = jetbrick.template.loader.ClasspathResourceLoader
生产的jar文件可以读取模板文件,使用launch4j后就不能读取了,不知道什么原因
扩展方法:
public static String link(String title, String title, String ... attributes) {
...
return ...
}
Error message:
template: /include/layout.jetx: 29,41
------------------------------------------------------------------------------------------------
27: <nav class="navbar navbar-inserse navbar-fixed-top" role="navigation">
28: <div class="container-fluid">
29: <div class="navbar-header">${"??".link("/")}</div>
^ -- here
30:
31: <div id="navbar" class="navbar-collapse collapse">
------------------------------------------------------------------------------------------------
] with root cause
java.lang.IllegalArgumentException: argument type mismatch <4 internal calls>
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve/java:79)
RT
模板所在位置如:/Users/biezhi/workspace/a b/demo/hello.html
访问的时候回提示:
jetbrick.io.resource.ResourceNotFoundException
在不带空格的目录正常,不知道中文的目录会不会有问题
在springside4的showcase中通过嵌入式jetty快速重启抛异常,
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jetbrick.template.web.springmvc.JetTemplateViewResolver#0' defined in ServletContext resource [/WEB-INF/spring-mvc.xml]: Invocation of init method failed; nested exception is java.lang.IllegalStateException: JetEngine has been created
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1568) ~[spring-beans-4.1.2.RELEASE.jar:4.1.2.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:540) ~[spring-beans-4.1.2.RELEASE.jar:4.1.2.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476) ~[spring-beans-4.1.2.RELEASE.jar:4.1.2.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:302) ~[spring-beans-4.1.2.RELEASE.jar:4.1.2.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:229) ~[spring-beans-4.1.2.RELEASE.jar:4.1.2.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298) ~[spring-beans-4.1.2.RELEASE.jar:4.1.2.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193) ~[spring-beans-4.1.2.RELEASE.jar:4.1.2.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:762) ~[spring-beans-4.1.2.RELEASE.jar:4.1.2.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757) ~[spring-context-4.1.2.RELEASE.jar:4.1.2.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480) ~[spring-context-4.1.2.RELEASE.jar:4.1.2.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:663) ~[spring-webmvc-4.1.2.RELEASE.jar:4.1.2.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:629) ~[spring-webmvc-4.1.2.RELEASE.jar:4.1.2.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:677) ~[spring-webmvc-4.1.2.RELEASE.jar:4.1.2.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:548) ~[spring-webmvc-4.1.2.RELEASE.jar:4.1.2.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:489) ~[spring-webmvc-4.1.2.RELEASE.jar:4.1.2.RELEASE]
at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136) [spring-webmvc-4.1.2.RELEASE.jar:4.1.2.RELEASE]
at javax.servlet.GenericServlet.init(GenericServlet.java:244) [javax.servlet-api-3.1.0.jar:3.1.0]
at org.eclipse.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:612) [jetty-all-9.2.5.v20141112.jar:9.2.5.v20141112]
at org.eclipse.jetty.servlet.ServletHolder.initialize(ServletHolder.java:395) [jetty-all-9.2.5.v20141112.jar:9.2.5.v20141112]
at org.eclipse.jetty.servlet.ServletHandler.initialize(ServletHandler.java:871) [jetty-all-9.2.5.v20141112.jar:9.2.5.v20141112]
at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:298) [jetty-all-9.2.5.v20141112.jar:9.2.5.v20141112]
at org.eclipse.jetty.webapp.WebAppContext.startWebapp(WebAppContext.java:1343) [jetty-all-9.2.5.v20141112.jar:9.2.5.v20141112]
at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1336) [jetty-all-9.2.5.v20141112.jar:9.2.5.v20141112]
at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:741) [jetty-all-9.2.5.v20141112.jar:9.2.5.v20141112]
at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:499) [jetty-all-9.2.5.v20141112.jar:9.2.5.v20141112]
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) [jetty-all-9.2.5.v20141112.jar:9.2.5.v20141112]
at org.springside.modules.test.jetty.JettyFactory.reloadContext(JettyFactory.java:84) [test-classes/:na]
at org.springside.examples.showcase.ShowcaseServer.main(ShowcaseServer.java:35) [test-classes/:na]
Caused by: java.lang.IllegalStateException: JetEngine has been created
at jetbrick.template.web.JetWebEngine.create(JetWebEngine.java:52) ~[jetbrick-template-web-2.0.3.jar:2.0.3]
at jetbrick.template.web.springmvc.JetTemplateViewResolver.afterPropertiesSet(JetTemplateViewResolver.java:54) ~[jetbrick-template-springmvc-2.0.3.jar:2.0.3]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1627) ~[spring-beans-4.1.2.RELEASE.jar:4.1.2.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1564) ~[spring-beans-4.1.2.RELEASE.jar:4.1.2.RELEASE]
... 27 common frames omitted
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.