java - How do I suppress additional content in freemarker template file?
问题描述
My company uses java lite (active web) and freemarker templates for display in some legacy web pages. I wrote an active web AppController which is forwarding to an ftl display file (freemarker template) and I'm able to see the 'hello world' content. However somehow the page is also getting our standard web site header and footer content and I have no idea how to suppress that or where to look. Is there some global configuration for javalite that says to include headers and footers for all pages and can it be supressed?
public class MfaController extends AppController {
@GET
public void registration() {
//does nothing
}
}
registration.ftl:
<html>
<body>hello world</body>
</html>
解决方案
JavaLite is not using configuration files. Instead it uses conventions. What you observe is a default behavior. The default layout located in
src/main/webapp/WEB-INF/views/layouts/default_layout.ftl
is applied to all web pages, unless you tell the framework you do not need it.
If you do not want a layout, you can turn it off by overriding a getLayout()
method:
public class MfaController extends AppController {
public void registration() {
//does nothing
}
public String getLayout(){
return null;
}
}
A alternative solution will look like this:
public class MfaController extends AppController {
public void registration() {
render().noLayout();
}
}
Also, the @GET
annotation is redundant, all actions are GET by default if public.
Here is the docs: https://javalite.io/views#default-layout
推荐阅读
- java - 测试使用扫描仪对象的方法
- python-3.7 - ascii 输入的数据验证
- amazon-web-services - EKS cron 作业部署失败
- ios - 我应该为 altool 命令行使用哪个密码?
- css - CSS 按钮中央修复
- android - 无法在 android 上将 Chancejs 与 rhino 一起使用
- javascript - 使用 javascript 显示和隐藏元素和切换图标
- symfony - symfony + API 平台。如何验证日期类型过滤器的格式?
- python - 在 Django 中,我无法从数据库中检索所选值,其状态字段中的下拉列表也无法在上传 cv 中检索所选文件
- node.js - 错误:“断开连接”是保留的事件名称,为什么会出现此错误?