过滤器把样式过滤掉,无法显示样式问题, 处理方法

/**
 * 解决全站乱码问题,处理所有的请求
 */
public class CharchaterFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
    }

    @Override
    public void doFilter(ServletRequest req, ServletResponse rep, FilterChain filterChain) throws IOException, ServletException {
        //将父接口转为子接口
        HttpServletRequest request = (HttpServletRequest) req;
        HttpServletResponse response = (HttpServletResponse) rep;
        //获取请求方法
        String method = request.getMethod();
        //解决post请求中文数据乱码问题
        if(method.equalsIgnoreCase("post")){
            request.setCharacterEncoding("utf-8");
        }
      //加个判断 跳过js css 就好了
        String s = ((HttpServletRequest) req).getRequestURL().toString();
        if (!(s.contains("/css")||s.contains("js"))) {
            response.setContentType("text/html;charset=utf-8");
        }
        filterChain.doFilter(request,response);
    }

    @Override
    public void destroy() {

    }
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
UEditor编辑器的默认配置是自动过滤Style内联样式的,这是为了避免恶意代码的注入和提高编辑器的安全性。如果你需要在编辑器中使用一些特定的内联样式,可以通过修改UEditor的配置来实现。具体的方法是在UEditor的配置文件中添加如下代码: ``` //允许的标签 allowDivTransToP: false, allowScript: false, allowSpanTransToP: false, filterRules: { //允许的标签和属性 'p': {'$': {}}, 'br': {'$': {}}, 'u': {'$': {}}, 'strong': {'$': {}}, 'em': {'$': {}}, 'font': {'$': {'color': 1, 'face': 1, 'size': 1}}, 'span': {'$': {'style': 1, 'class': 1}}, 'a': {'$': {'href': 1, 'target': 1, 'title': 1}}, 'img': {'$': {'src': 1, 'width': 1, 'height': 1, 'border': 1, 'alt': 1, 'title': 1}}, 'table': {'$': {'width': 1, 'border': 1, 'cellpadding': 1, 'cellspacing': 1, 'bgcolor': 1, 'align': 1}}, 'tbody': {'$': {}}, 'tr': {'$': {'bgcolor': 1, 'height': 1, 'align': 1}}, 'td': {'$': {'width': 1, 'height': 1, 'valign': 1, 'align': 1, 'colspan': 1, 'rowspan': 1, 'bgcolor': 1}} }, //过滤样式 filterStyle: true, //过滤CSS filterCss: true ``` 在上述代码中,filterStyle参数设置为true表示开启过滤样式的功能,如果需要允许某些特定的样式,可以在filterRules中添加对应的样式属性。 如果你的UEditor版本较老,可能需要手动修改UEditor的源码来实现此功能。可以在UEditor源码的ueditor.config.js文件中查找“filterStyle”关键字,然后将其设置为false即可取消自动过滤样式的功能。但需要注意,这样做会降低编辑器的安全性,可能会存在安全隐患。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值