首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

filter批改请求参数

2013-11-15 
filter修改请求参数public class SpecialCharacterFilter{protected Log log LogFactory.getLog(getClas

filter修改请求参数

public class SpecialCharacterFilter  {protected Log log = LogFactory.getLog(getClass());@Overrideprotected void doFilterInternal(HttpServletRequest req,HttpServletResponse res, FilterChain chain)throws ServletException, IOException {req.setCharacterEncoding("utf-8");Map map = req.getParameterMap();Set set = map.entrySet();if (map != null) {for (Iterator it = set.iterator(); it.hasNext();) {Map.Entry entry = (Entry) it.next();if (entry.getValue() instanceof String[]) {String[] values = (String[]) entry.getValue();for (int i = 0; i < values.length; i++) {//html特殊字符转义//values[i] = HtmlUtils.htmlEscape(values[i]);//Sql转义values[i]=StringEscapeUtils.escapeSql(values[i]);//javascript特殊字符转义//values[i] = JavaScriptUtils.javaScriptEscape(values[i]);entry.setValue(values);}}}chain.doFilter(req, res);}}}

?

热点排行