五.SpringMVC+MyBatis搭建安全与性能

来源:互联网 发布:西部数码域名管理 编辑:程序博客网 时间:2024/05/17 09:37

一.XSS跨站脚本,SQL注入
XSS跨站脚本:
如:盗取用户Cookie、破坏页面结构、重定向到其它网站

<html>    <head>       <title>XSS测试</title>    </head>    <body>       页面内容:<%=request.getParameter("content")%>    </body></html>http://www.domain.com/test.jsp?content=<script>alert('XSS注入');</script>

SQL注入:SQL命令插入到Web表单递交或输入域名或页面请求的查询字符串
如:

http://www.example.com/user?userId=1select * from table_user where userId=${userId}但是:http://www.example.com/user?userId=1 or 1=1select * from table_user where userId=1 or 1=1偷来数据库信息

二.防止:定义一个Filter,使用HttpServletRequestWrapper类截获并处理参数:

定义一个类extends HttpServletRequestWrapper。

filter中:

xxxwapper request = new xxxwapper((HttpServletRequest) servletRequest);filterChain.doFilter(request,servletResponse);

三.提升性能:mybatis缓存
三个配置就搞定:

第一个需要配置config.xml,开启缓存<setting name="cacheEnabled" value="true" />第二个需要在Mapper文件头指定使用缓存<cache readOnly="true" size="500" flushInterval="120000" eviction="LRU"/>第三个配置,在具体的SQL语句处指定使用缓存,默认开启<select id="selectCount" useCache="true">...</select>

缓存策略:
LRU,最近最少使用,移除最长时间不被使用的对象,默认策略
FIFO,先进先出,按对象进入缓存的顺序来移除它们
SOFT,软引用,移除基于垃圾回收器状态和软引用规则的对象
WEAK,弱引用,更积极地移除基于垃圾收集器状态和弱引用规则的对象

0 0