velocity 的 escape实现
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> 输出 <script>alert(/xxx/)</script>
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实现的更多相关文章
- maven+springmvc+spring+mybatis+velocity整合
一.ssmm简介 ssmm是当下企业最常用的开发框架架构 maven:管理项目jar包,构建项目 spring:IOC容器,事务管理 springmvc:mvc框架 myBatis:持久层框架 v ...
- HDU 3533 Escape (BFS + 预处理)
Escape Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total S ...
- 《Velocity java开发指南》中文版(下)转载
文章出自:http://sakyone.iteye.com/blog/524292 8.Application Attributes Application Attributes (应用程序属性)是和 ...
- 《Velocity 模板使用指南》中文版[转]
转自:http://blog.csdn.net/javafound/archive/2007/05/14/1607931.aspx <Velocity 模板使用指南>中文版 源文见 htt ...
- HDU 3533 Escape(bfs)
Escape Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su ...
- HDU 3533 Escape(大逃亡)
HDU 3533 Escape(大逃亡) /K (Java/Others) Problem Description - 题目描述 The students of the HEU are maneu ...
- 【算法】Escape
The students of the HEU are maneuvering for their military training. The red army and the blue army ...
- Velocity初始化过程解析
velocity就是由template,engine,context组成. 1.首先创建一个template(如果是用在web上就是一个html文件),将需要参数化或实例化的地方用跟context有关 ...
- HDU3533 Escape —— BFS / A*算法 + 预处理
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3533 Escape Time Limit: 20000/10000 MS (Java/Others) ...
随机推荐
- velcoity使用说明:foreach指令
http://blog.csdn.net/madding/article/details/6641020当在velocity中需要显示一个列表信息,我们会用foreach循环输出, 要求: 假如现在需 ...
- EMQ ---100万线连接测试说明
注解 EMQ 2.0 消息服务器默认设置,允许最大客户端连接是512,因为大部分操作系统 ‘ulimit -n’ 限制为1024. EMQ 消息服务器1.1.3版本,连接压力测试到130万线,8核心/ ...
- internet与Internet的区别
internet是用一个共同的协议族把多个网络连接在一起.而Internet指的是世界范围内通过TCP/IP互相通信的所有主机集合(超过1 0 0万台).Internet是一个internet,但in ...
- ConcurrentHashMap的JDK1.8实现
今天我们介绍一下ConcurrentHashMap在JDK1.8中的实现.基本结构 ConcurrentHashMap在1.8中的实现,相比于1.7的版本基本上全部都变掉了.首先,取消了Segment ...
- Chrome插件开发之manifest.json
广而告之: Chrome插件之一键保存网页为PDF1.1发布 http://www.cnblogs.com/bdstjk/p/3179543.html 最近做“一键保存网页为PDF”过程中,对Chro ...
- SQL数据库 CRUD
1.删除表 drop table +表名 2.修改表 alter table+表名+ add(添加)+列名+ int(类型) alter table+表名+ drop(删除)+column(列) ...
- CPU亲和力
http://blog.chinaunix.net/uid-27714502-id-3515874.html http://www.tuicool.com/articles/I7NFzy http:/ ...
- Android开发学习秘籍笔记(十九)
吼.花了2天最后做出了一个类似于蓝牙串口助手功能的小程序,事实上也是实习公司的要求---有一个蓝牙无线扫描枪,要求终端能够通过蓝牙连接到该设备,而且蓝牙无线扫描枪扫描二维码或者条形码的时候能够将二维码 ...
- UTF-8和GBK的区别
GBK是在国家标准GB2312基础上扩容后兼容GB2312的标准(好像还不是国家标准).GBK编码专门用来解决中文编码的,是双字节的.不论中英文都是双字节的. UTF-8编码是用以解决国际上字符的一种 ...
- Linux 比较重要且难掌握命令 集合
1. find find path –option [-print] [-exec command] {} \; find . -maxdepth 1 -name aa find . -maxdept ...