网页静态化与bease64加密cookie

(这是学习笔记)

1.网页静态化

关于网页静态化我使用的是VelocityHelper实现的。

关键的部分如下

  •   public static String velocity(String templatePath,String templateName, Map<String, Object> map) {


    try {
    VelocityEngine ve = new VelocityEngine();
    // 配置velocity引擎 也可通过配置文件和Properties来配置
    // ve.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath");
    // ve.setProperty("classpath.resource.loader.class",
    // ClasspathResourceLoader.class.getName());
    // 设置编码
    ve.setProperty(Velocity.ENCODING_DEFAULT, "UTF-8");
    ve.setProperty(Velocity.INPUT_ENCODING, "UTF-8");
    ve.setProperty(Velocity.OUTPUT_ENCODING, "UTF-8");
    ve.setProperty(Velocity.FILE_RESOURCE_LOADER_PATH, templatePath);
    Object s = ve.getProperty(Velocity.FILE_RESOURCE_LOADER_PATH);

    // 初始化
    ve.init();
    // 模板地址
    Template t = ve.getTemplate(templateName);
    // 构造VelocityContext,将数值传入Context
    VelocityContext ctx = new VelocityContext(map);
    // 输出字符串
    StringWriter sw = new StringWriter();
    // 像模板串字符串,并得字符
    t.merge(ctx, sw);


    // System.out.println(sw.toString());
    return sw.toString();
    } catch (Exception e) {
    e.printStackTrace();
    throw new RuntimeException(e.toString());


    }
    }

  • 其中templatePath模板目录 (相对路径)  templateName是模板名称(一般是 ×××.vm) 

    在模板里,把要替换的值只能是map集合,在×××.vm中,你把变动的值用(假设是一个对象)用$(key).(属性名)()            eg: $b.name()这样就能将值传入模板中

    假设传入的值是list集合要循环

    #foreach($p in $list)

    $p.(属性名)()

    #end

    这样来遍历


    2.base64加密解密

    1.  byte[] encodeBase64 = Base64.encodeBase64(“asv”.getBytes());   
    2.           
    3.  byte[] decodeBase64 = Base64.decodeBase64(encodeBase64);  

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值