过滤器中的代码:
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest req = (HttpServletRequest) request; HttpServletResponse resp = (HttpServletResponse) response; chain.doFilter(new HTMLCharacterRequest(req), resp); }
HTMLCharacterRequest:
public HTMLCharacterRequest(HttpServletRequest request) { super(request); } @Override public String getParameter(String name) { return filter(super.getParameter(name)); } private String filter(String parameter) { if(StringHelper.isNullOrEmpty(parameter)){ return null; } return StringEscapeUtils.escapeSql(StringHelper.unescape(parameter)); }
这样过滤后 在Controller里面可以使用request.getParameter("xxx")的方式可以获取到处理之后的信息,例如:
前台传递的参数为:escase("你好!")
通过request.getParameter("xxx") 能够获取到 "你好!"
但是通过注解的方式却是未解码的数据:
@RequestMapping("addNewProvince") public @ResponseBody Map<String, Object> addNewProvince( @RequestParam("provinceName") String provinceName, @RequestParam("operatorType") String operatorType, @RequestParam("desc") String desc, HttpServletRequest request)
什么原因啊?