前端编辑保存富文本,后端抛出异常JSON parse error: Unexpected character (’’ (code 92)),导致实体类接收不到数据,原因是富文本内容为html,包含特殊符号,实体类无法解析
import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
/**
* XSS过滤
*/
public class XssFilter implements Filter {
List<String> ignoreXSSURIList = new ArrayList<>();
//将富文本保存编辑接口添加到忽略列表中
public XssFilter(){
ignoreXSSURIList.add("/sys/user/update");
ignoreXSSURIList.add("/sys/user/save");
}
@Override
public void init(FilterConfig config) throws ServletException {
}
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
if(!ignoreXSSURIList.contains(((HttpServletRequest) request).getRequestURI())){
XssHttpServletRequestWrapper xssRequest = new XssHttpServletRequestWrapper(
(HttpServletRequest) request);
chain.doFilter(xssRequest, response);
}else {
chain.doFilter(request, response);
}
}
@Override
public void destroy() {
}
}