这是我Config的配置
@Override
public void configConstant(Constants constants) {
loadProp("pro_db_config.txt", "dev_db_config.txt");
constants.setViewType(ViewType.JFINAL_TEMPLATE);
constants.setBaseUploadPath("/uploadFile");
constants.setEncoding("utf-8");
constants.setDevMode(PropKit.getBoolean("devMode", true));
}
@Override
public void configRoute(Routes routes) {
routes.add(new UserRoutes());
}
路由的配置
public class UserRoutes extends Routes {
@Override
public void config() {
setBaseViewPath("/WEB-INF/html");
System.out.println(getBaseViewPath());
add("/user", UserController.class);
}
}
controller里面的方法:
@ActionKey("/registerssssss ")
public void register() {
render("/registerbbbbbbbbb/registeraaaa.html");
}
我的工程路径:
当我访问http://localhost:8088/registerssssss 的时候,报错:
Starting JFinal 3.4 Starting web server on port: 8088 /WEB-INF/html Starting Complete. Welcome To The JFinal World :) JFinal-3.4 action report -------- 2018-11-08 13:48:29 -------------------------- Url : GET /registerssssss Controller : com.edulab.controller.user.UserController.(UserController.java:1) Method : register Interceptor : com.edulab.interceptor.GlobalInterceptor.(GlobalInterceptor.java:1) -------------------------------------------------------------------------------- 2018-11-08 13:48:29 [ERROR]-[Thread: qtp1190524793-24]-[com.jfinal.core.ActionHandler.handle()]: /registerssssss java.lang.RuntimeException: File not found : E:\JavaEE\IDEA\edulabinnovation\src\main\webapp/WEB-INF/html/user/register.html at com.jfinal.template.source.FileSource.getContent(FileSource.java:70) at com.jfinal.template.Engine.buildTemplateBySourceFactory(Engine.java:154) at com.jfinal.template.Engine.getTemplate(Engine.java:139) at com.jfinal.render.TemplateRender.render(TemplateRender.java:61) at com.jfinal.core.ActionHandler.handle(ActionHandler.java:103) at com.jfinal.ext.handler.ContextPathHandler.handle(ContextPathHandler.java:48) at com.jfinal.core.JFinalFilter.doFilter(JFinalFilter.java:73) at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1307) at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449) at org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365) at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90) at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83) at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:387) at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362) at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125) at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1307) at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:453) at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:137) at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:560) at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:231) at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1072) at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:382) at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:193) at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1006) at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135) at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116) at org.eclipse.jetty.server.Server.handle(Server.java:365) at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:485) at org.eclipse.jetty.server.AbstractHttpConnection.headerComplete(AbstractHttpConnection.java:926) at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.headerComplete(AbstractHttpConnection.java:988) at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:635) at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:235) at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82) at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:628) at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:52) at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608) at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543) at java.lang.Thread.run(Thread.java:748) 2018-11-08 13:48:29 [ERROR]-[Thread: qtp1190524793-24]-[com.jfinal.core.JFinalFilter.doFilter()]: /registerssssss java.lang.IllegalStateException: STREAM at org.eclipse.jetty.server.Response.getWriter(Response.java:699) at com.jfinal.render.ErrorRender.render(ErrorRender.java:59) at com.jfinal.core.ActionHandler.handle(ActionHandler.java:141) at com.jfinal.ext.handler.ContextPathHandler.handle(ContextPathHandler.java:48) at com.jfinal.core.JFinalFilter.doFilter(JFinalFilter.java:73) at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1307) at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449) at org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365) at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90) at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83) at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:387) at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362) at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125) at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1307) at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:453) at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:137) at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:560) at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:231) at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1072) at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:382) at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:193) at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1006) at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:135) at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116) at org.eclipse.jetty.server.Server.handle(Server.java:365) at org.eclipse.jetty.server.AbstractHttpConnection.handleRequest(AbstractHttpConnection.java:485) at org.eclipse.jetty.server.AbstractHttpConnection.headerComplete(AbstractHttpConnection.java:926) at org.eclipse.jetty.server.AbstractHttpConnection$RequestHandler.headerComplete(AbstractHttpConnection.java:988) at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:635) at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:235) at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:82) at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:628) at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:52) at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:608) at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:543) at java.lang.Thread.run(Thread.java:748)
我想要在render这里渲染register这个文件怎么做啊!!!!!
项目:JFinal
上面的三项:
1:baseViewPath 为 "/WEB-INF/html"
2:viewPath 为 "/user",这个值是在 add("/user", UserController.class) 时第三个参数指定的,而你第三个参数省略了,默认与第一个参数相同,即为 "/user"
3:view 为 "/registerbbbbbbbbb/registeraaaa.html" 来自于这行代码:render("/registerbbbbbbbbb/registeraaaa.html")
finalView 为 "/WEB-INF/html/user/registerbbbbbbbbb/registeraaaa.html"
但是,注意这里看但是,你的 render 方法中的 view 是以 "/" 打头的,所以 baseViewPath、viewPath 不起作用,所以你的 finalView 实际上为:
"/registerbbbbbbbbb/registeraaaa.html"
根据上面规则找到原因解决一下即可。
简单一句话:
finalView = baseViewPath + viewPath + view, 当 view 以 "/" 打头时前两项当成不存在