在ftp中填充数据模型
来源:互联网 发布:郑州大学网络自助平台 编辑:程序博客网 时间:2024/06/06 17:34
test.fl文档:
<html><head> <title>Welcome!</title></head><body><h1>Welcome ${user}!</h1><p>Our latest product: <a href="${latestProduct.url}">${latestProduct.name}</a>!</body></html>
servlet中利用free marker来获取并填充数据模型:
package cmz.alvin.ftl;import freemarker.template.Configuration;import freemarker.template.Template;import freemarker.template.TemplateException;import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import java.io.IOException;import java.io.Writer;import java.util.HashMap;import java.util.Map;/** * Created by alvin on 16/1/21. */public class HelloFreeMarker extends HttpServlet { private Configuration cfg; public void init() { //初始化FreeMarker配置 //创建一个Configuration实例 cfg = new Configuration(); //设置FreeMarker的模版文件位置 cfg.setServletContextForTemplateLoading(getServletContext(), "WEB-INF/templates"); } public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { //建立数据模型 Map root = new HashMap(); root.put("user", "Big Joe"); Map latest = new HashMap(); root.put("latestProduct", latest); latest.put("url", "/ftl"); latest.put("name", "green mouse"); //取得模版文件 Template t = cfg.getTemplate("test.ftl"); // 开始准备生成输出 // - 使用模版文件的charset作为本页面的charset // - 使用text/html MIME-type response.setContentType("text/html; charset=" + t.getEncoding()); Writer out = response.getWriter(); //合并数据模型和模版,并将结果输出到out中 try { t.process(root, out); } catch (TemplateException e) { throw new ServletException("处理Template模版中出现错误", e); } }}
0 0
- 在ftp中填充数据模型
- 在Powerdesigner中创建概念数据模型
- 在powerdesigner中创建物理数据模型
- 在Powerdesigner中创建概念数据模型
- 在powerdesigner中创建物理数据模型
- 在as3isolib中 给对象填充颜色
- ADO.NET实体数据模型 在模型中加入外键列【Linq】
- 在EA中画ER图和数据模型图
- Powerdesigner可以在数据模型中方便地生成测试数据
- 在Option条目中填充前导空格的方法
- 在Option条目中填充前导空格的方法
- 在Option条目中填充前导空格的方法
- 在Option条目中填充前导空格的方法
- 在Option条目中填充前导空格的方法
- 在VB6.0中实现大面积不规则区域的填充
- 如何在Cell 组件/插件中优化数据填充速度
- 在autocad中对二维图形的颜色填充
- Code70在Asp.NET中填充DropDownList颜色
- 真机运行程序Xcode提示The identity used to sign the executable is no longer valid
- 画表格
- JSONObject 解析json
- 高仿微信朋友圈
- [DeepLearning] 深度学习框架Caffe初体验之病斑检测
- 在ftp中填充数据模型
- ros_opencv_按下键p从kinect获取一张一定大小的图片并处理
- 通俗易懂的正则表达式
- 关闭Eclipse按空格和等号键自动补全内容
- lua基本实验
- sql基础03—数据类型
- 非UI主线程如何弹出Toast以及Handler.post()流程分析
- java mail(发送邮件--163邮箱)
- [ElasticSearch] mappings and type