zoukankan      html  css  js  c++  java
  • freemaker小练习

    public class TestFreemaker extends HttpServlet{
        // 负责管理FreeMarker模板的Configuration实例  
        private Configuration cfg = null;  
        public void init() throws ServletException {  
            // 创建一个FreeMarker实例  
            cfg = new Configuration();  
            // 指定FreeMarker模板文件的位置  
    //        cfg.setServletContextForTemplateLoading(getServletContext(),"/WEB-INF/templates");  
            cfg.setClassForTemplateLoading(TestFreemaker.class, "/templates");
        }  
        @SuppressWarnings("unchecked")  
        public void doPost(HttpServletRequest request, HttpServletResponse response)  
                throws ServletException, IOException {  
            // 建立数据模型  
            Map root = new HashMap();  
            root.put("message", "hello world======");  
            root.put("name", "hhhhhh");  
            // 获取模板文件  
            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) {  
                e.printStackTrace();  
            }  
        }  
        public void doGet(HttpServletRequest request, HttpServletResponse response)  
                throws ServletException, IOException {  
            doPost(request, response);  
        }  
        public void destroy() {  
            super.destroy();  
        } 

  • 相关阅读:
    微信退款回调
    laravel5.5 自定义验证规则——手机验证RULE
    laravel5.5 延时队列的使用
    laravel 使用EasyWechat 3分钟完成微信支付(以APP支付为例)
    第三章预习
    预习2
    预习原码补码
    C语言ll作业01
    C语言寒假大作战04
    C语言寒假大作战03
  • 原文地址:https://www.cnblogs.com/ly-china/p/5567701.html
Copyright © 2011-2022 走看看