美文网首页
编辑源码解决ueditor jsp版本跨域问题!

编辑源码解决ueditor jsp版本跨域问题!

作者: bullion | 来源:发表于2019-05-08 10:56 被阅读0次

1)下载源码ueditor-1.4.3.3

2)使用IDEA新建项目拉入源码,具体可参考 Ueditor官网

3)确保启动源码后可访问到

4)增加拦截器CorsFilter类

CorsFilter

package com.baidu.ueditor.wb;

import javax.servlet.*;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

import java.io.IOException;

public class CorsFilter implements Filter {

    @Override

    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override

    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain) throws IOException, ServletException {

        HttpServletResponse response = (HttpServletResponse) servletResponse;

        response.setHeader("Access-Control-Allow-Origin", "*");

        response.setHeader("Access-Control-Allow-Methods", "PUT,POST,GET,DELETE,OPTIONS");

        response.setHeader("Access-Control-Max-Age", "3600");

        response.setHeader("Access-Control-Allow-Headers", "X-Requested-With,X_Requested_With");

        HttpServletRequest request = (HttpServletRequest) servletRequest;

        if (request.getMethod().equals("OPTIONS")) {

            return;

        }

        chain.doFilter(request, response);

    }

    @Override

    public void destroy() {

    }

}

5)编辑web.xml

<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"

        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

        xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"

        version="4.0">

    <welcome-file-list>

        <welcome-file>index.html</welcome-file>

    </welcome-file-list>

    <filter>

        <filter-name>corsFilter</filter-name>

        <filter-class>com.baidu.ueditor.wb.CorsFilter</filter-class>

    </filter>

    <filter-mapping>

        <filter-name>corsFilter</filter-name>

        <url-pattern>/*</url-pattern>

    </filter-mapping>

</web-app>

相关文章

网友评论

      本文标题:编辑源码解决ueditor jsp版本跨域问题!

      本文链接:https://www.haomeiwen.com/subject/phxmoqtx.html