九十八、freemarker框架报错 s.e.ErrorMvcAutoConfiguration$StaticView : Cannot render error page for request

简介: 九十八、freemarker框架报错 s.e.ErrorMvcAutoConfiguration$StaticView : Cannot render error page for request

报错信息


14.png


2022-04-22 12:59:38.904 ERROR 16164 --- [nio-8888-exec-1] freemarker.runtime                       : Error executing FreeMarker template


freemarker.core.InvalidReferenceException: The following has evaluated to null or missing:

==> pageContext  [in template "courseAdd.html" at line 84, column 29]


----

Tip: If the failing expression is known to legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing</#if>. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)??

----


----

FTL stack trace ("~" means nesting-related):

   - Failed at: ${pageContext.request.contextPath}  [in template "courseAdd.html" at line 84, column 27]

----


后端代码


15.png


前端代码


16.png


其功能要实现下拉框,添加了option却显示不出来(如下图),并且后端数据已经拿到(打印在控制台了),心想就是前端这里拿不到数据。


17.png



回头看报错信息,发现


o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is freemarker.core.InvalidReferenceException: The following has evaluated to null or missing:


大致意思为:Servlet请求处理失败,可能为空值或缺失值


问题分析


那应该就是空值的问题,导致下拉框无法正常显示,teacherNames中存在空值


看日志 给出了处理办法即(上方标红加粗的提示) 添加

<div class="layui-input-block">
<!--                <#if myOptionalVar??>when-present<#else>when-missing</#if>-->
                <select id="baseCourseSelect" lay-search>
                    <option>--请选择——</option>
                        <#list teacherNames as tname>
                    <option value="${tname}">${tname}</option>
                        </#list>
                </select>
            </div>

后来通过查找找到了最终解决方法:


问题解决


在配置项(application.yml)中加入全局去空值的设置:


spring.freemarker.settings.classic_compatible= true

18.png


注意 true 前面有一个空格,不然不会生效。


最终效果


19.png

相关文章
|
7月前
uView queryParams 对象转URL参数
uView queryParams 对象转URL参数
77 0
|
4月前
|
JavaScript 前端开发
vue引入axios出现Module parse failed: Unexpected token (5:2)
vue引入axios出现Module parse failed: Unexpected token (5:2) 页面显示 Cannot GET /
148 2
|
Web App开发 JavaScript 前端开发
解决DevTools failed to load SourceMap Could not load content for .js.map HTTP error code 404 问题
解决DevTools failed to load SourceMap Could not load content for .js.map HTTP error code 404 问题
904 0
|
前端开发 Java 程序员
SpringBoot中ErrorPage(错误页面)的使用--【ErrorPage组件】
SpringBoot中ErrorPage(错误页面)的使用--【ErrorPage组件】 CSDN 转过来的,所以格式与内容有些许错误请见谅
thinkphp报错Call to undefined method app\index\controller\Index::fetch()
thinkphp报错Call to undefined method app\index\controller\Index::fetch()
181 0
报错 An error happened during template parsing (template: “ServletContext resource [/shiroTest.html]“)
报错 An error happened during template parsing (template: “ServletContext resource [/shiroTest.html]“)
|
JSON 前端开发 Java
【elementUI + Spring报错解决方案】Required request part ‘*****‘ is not present
【elementUI + Spring报错解决方案】Required request part ‘*****‘ is not present
1051 0
【elementUI + Spring报错解决方案】Required request part ‘*****‘ is not present
|
前端开发 Go
Gin渲染html模板报错:ends in a non-text context: {stateHTMLCmt delimNone urlPartNone jsCtxRegexp attrNone
Gin渲染html模板报错:ends in a non-text context: {stateHTMLCmt delimNone urlPartNone jsCtxRegexp attrNone
154 0
Gin渲染html模板报错:ends in a non-text context: {stateHTMLCmt delimNone urlPartNone jsCtxRegexp attrNone
|
JavaScript
vue element-ui [Vue warn]: Invalid prop: custom validator check failed for prop “index“.
vue element-ui [Vue warn]: Invalid prop: custom validator check failed for prop “index“.
376 0
vue element-ui [Vue warn]: Invalid prop: custom validator check failed for prop “index“.
引入ElementUI 日历组件报错Module parse failed: Unexpected token (65:6)
引入ElementUI 日历组件报错Module parse failed: Unexpected token (65:6)
183 0
引入ElementUI 日历组件报错Module parse failed: Unexpected token (65:6)