EscapeHtmlReference的escape方法调用以下方法实现:
StringEscapeUtils.escapeHtml(param);  再调用
org.apache.commons.lang.Entities.HTML40.escape(writer, string);
代码如下:
public void escape(Writer writer, String str) throws IOException {
int len = str.length(); for(int i = 0; i < len; ++i) {
char c = str.charAt(i);
String entityName = this.entityName(c);
if(entityName == null) {
if(c > 127) {
writer.write("&#");
writer.write(Integer.toString(c, 10));
writer.write(59); //就是个分号
} else {
writer.write(c);
}
} else {
writer.write(38);
writer.write(entityName);
writer.write(59);
}
} } 我们也可以自己调用
StringEscapeUtils.escapeHtml(param);
比如:
String param = request.getParameter("p");
String x = StringEscapeUtils.escapeHtml(param);
System.out.println(x); 输入 <script>alert(/xxx/)</script> 输出 &lt;script&gt;alert(/xxx/)&lt;/script&gt; velocity 也可以自定义 EventHandler 处理xss,配置EscapeHtmlReference 替换成自己的EventHandler
<bean id="velocityConfigurer"
class="org.springframework.web.servlet.view.velocity.VelocityConfigurer">
<property name="resourceLoaderPath" value="/WEB-INF/pages/"/>
<property name="velocityProperties">
<props>
<prop key="input.encoding">utf-8</prop>
<prop key="output.encoding">utf-8</prop>
<prop key="eventhandler.referenceinsertion.class">org.apache.velocity.app.event.implement.EscapeHtmlReference</prop>
<prop key="eventhandler.escape.html.match">/^(?!\$\!?unesc_).*/</prop>
</props>
</property>
</bean>
												

velocity 的 escape实现的更多相关文章

  1. maven+springmvc+spring+mybatis+velocity整合

      一.ssmm简介 ssmm是当下企业最常用的开发框架架构 maven:管理项目jar包,构建项目 spring:IOC容器,事务管理 springmvc:mvc框架 myBatis:持久层框架 v ...

  2. HDU 3533 Escape (BFS + 预处理)

    Escape Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total S ...

  3. 《Velocity java开发指南》中文版(下)转载

    文章出自:http://sakyone.iteye.com/blog/524292 8.Application Attributes Application Attributes (应用程序属性)是和 ...

  4. 《Velocity 模板使用指南》中文版[转]

    转自:http://blog.csdn.net/javafound/archive/2007/05/14/1607931.aspx <Velocity 模板使用指南>中文版 源文见 htt ...

  5. HDU 3533 Escape(bfs)

    Escape Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Su ...

  6. HDU 3533 Escape(大逃亡)

    HDU 3533 Escape(大逃亡) /K (Java/Others)   Problem Description - 题目描述 The students of the HEU are maneu ...

  7. 【算法】Escape

    The students of the HEU are maneuvering for their military training. The red army and the blue army ...

  8. Velocity初始化过程解析

    velocity就是由template,engine,context组成. 1.首先创建一个template(如果是用在web上就是一个html文件),将需要参数化或实例化的地方用跟context有关 ...

  9. HDU3533 Escape —— BFS / A*算法 + 预处理

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3533 Escape Time Limit: 20000/10000 MS (Java/Others)  ...

随机推荐

  1. ORCAD应用小技巧

    1.位号复制 递增和不变 2.netlist log信息 3.off page页码对其 4.批量修改off page符号命名的方法 5.批量修改电源符号 6.capture中instance和Occu ...

  2. Titel Block不显示

    在原有原理图上New page时不显示Titel Block 解决办法:两种(1)(2) 方法1.在新建的原理图上右键选择Schematic Page Properties,按下图勾选即可 方法2.进 ...

  3. WebApi异常处理解决方案

    一.使用异常筛选器捕获所有异常 首先在App_Start里面新建一个类WebApiExceptionFilterAttribute.cs,继承ExceptionFilterAttribute,重写On ...

  4. DataUml Design 教程6-DataUML Design 1.1版本正式发布(支持PD数据模型)

    从DataUML Design正式发布到现在有两个月了,由于最近比较忙,到现在才发布1.1版本.以后本人会一直坚持不断完善DataUML Design软件,希望广大程序猿们多多支持. 一.1.1版本新 ...

  5. https原理与实践

    HTTPS 原理与证书实践   分类: Web应用   1.1 网络安全知识 1.1.1 网结安全出现背景 网络就是实现不同主机之间的通讯,网络出现之初利用TCP/IP协议簇的相关协议概念,已经满足了 ...

  6. ImageData

    http://www.html5china.com/HTML5features/canvas/20120501_3591.html 1.上下文对象 Context 有三个方法用来创建.读取和设置 Im ...

  7. python 面试题 string int

    str1 = 'hello' str2 = str1 str3 = str1 str4 = str1 str1 = '' int1 = 1 int2 = int1 int3 = int1 int4 = ...

  8. BestCoder Round #93 ABC

    A: 题目大意: 将数组划分成最少的段,每段的数两两不同. 题解:直接用一个map记录一个数是否出现过,贪心的每次取最多个数就好. B: 题目大意: 给出一个0-9组成的字符串,问能否删掉K个数字,使 ...

  9. ansible使用

    常用ad hoc命令, 如:ansible raleigh -m shell -a 'echo $TERM' ansible webservers -m service -a "name=h ...

  10. SharePoint2013导入Excel到列表

    using Microsoft.SharePoint; using System; using System.Collections.Generic; using System.ComponentMo ...