NutzCN Logo
问答 用ueditor时报错了,跨域了
发布于 2931天前 作者 shusheng 4453 次浏览 复制 上一个帖子 下一个帖子
标签: 跨域 mvc
ueditor.all.js?29c8:23838 OPTIONS http://starskybbs.ngrok.cc/starskybbs/ueditor/jsp/controller.jsp? sendAndInsertFile @ ueditor.all.js?29c8:23838(anonymous function) @ ueditor.all.js?29c8:23878
VM5253 8780236…:1 XMLHttpRequest cannot load http://starskybbs.ngrok.cc/starskybbs/ueditor/jsp/controller.jsp?. Response to preflight request doesn't pass access control check: The 'Access-Control-Allow-Origin' header contains multiple values '*, *', but only one is allowed. Origin 'http://172.16.28.4:8080' is therefore not allowed access.
ueditor.all.js?29c8:23838 XHR failed loading: POST "http://starskybbs.ngrok.cc/starskybbs/ueditor/jsp/controller.jsp?".sendAndInsertFile @ ueditor.all.js?29c8:23838(anonymous function) @ ueditor.all.js?29c8:23878
11 回复

是的,跨域时,option请求不通过

入口方法加个

@Filters(@By(type=CrossOriginFilter.class))

ueditor自动帮我们上传了图片,没有入口方法啊,能不能继承一下CrossOriginFilter,或者过滤一下?

public class CorsFilter implements Filter {

	@Override
	public void init(FilterConfig filterConfig) throws ServletException {
	}

	@Override
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException,
			ServletException {
		// TODO Auto-generated method stub
		
		HttpServletResponse res = (HttpServletResponse) response;

		res.setContentType("text/html;charset=UTF-8");

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

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

		   res.setHeader("Access-Control-Max-Age", "0");

		   res.setHeader("Access-Control-Allow-Headers", "Origin, No-Cache, X-Requested-With, If-Modified-Since, Pragma, Last-Modified, Cache-Control, Expires, Content-Type, X-E4M-With,userId,token");

		   res.setHeader("Access-Control-Allow-Credentials", "true");

		   res.setHeader("XDomainRequestAllowed","1");

		   chain.doFilter(request, response);
		chain.doFilter(request, response);
	}

	@Override
	public void destroy() {
	}

}

写了自己的过滤器,这样过滤可以实现吗?

何不用CrossOriginFilter?

这个是提交到它自己的处理类里面去了。。。

访问JSP的时候? 那就你的Filter应该ok啦

单步调试了一下,先进入了 controller.jsp 执行上传后才进入filter

web.xml没配好,没让你的Filter拦截forward请求??

添加回复
请先登陆
回到顶部