3.7K Star 11.7K Fork 4.6K

卓源软件 / JeeSite 4.2

 / 详情

前端接口调用 跨域问题

Backlog
Opened this issue  
2021-04-20 11:21

shiro已去掉注释,功能已开启,前端调用接口还是有跨域问题,还有其他环节需要处理吗?

输入图片说明

Comments (3)

亚特兰蒂斯 created任务
展开全部操作日志

贴出你的错误信息,确认有没有生效,看请求地址的响应头

这是错误信息:
输入图片说明

yml设置:
输入图片说明

我自己在Application加入以下代码,不再报错。但是感觉方案不优雅,本身系统自带的有,问题不知出在哪里?

    public class crosFilter implements Filter {
        @Override
        public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws IOException, ServletException {
            HttpServletRequest request = (HttpServletRequest) req;
            HttpServletResponse response = (HttpServletResponse) resp;
            response.setHeader("Access-control-Allow-Origin", request.getHeader("Origin"));
            response.setHeader("Access-Control-Allow-Credentials", "true");
            response.setHeader("Access-Control-Allow-Headers", request.getHeader("Access-Control-Request-Headers"));
            response.addHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE, PUT");
            if ("OPTIONS".equals(request.getMethod())) {
                response.setStatus(HttpStatus.NO_CONTENT.value());
                return;
            } else {
                chain.doFilter(request, response);
            }
        }
    }

    @Bean
    public FilterRegistrationBean replaceTokenFilter() {
        FilterRegistrationBean registration = new FilterRegistrationBean();
        registration.setDispatcherTypes(DispatcherType.REQUEST);
        registration.setFilter(new crosFilter());
        registration.addUrlPatterns("/*");
        registration.setName("crosFilter ");
        registration.setOrder(1);
        return registration;
    }

Sign in to comment

状态
Assignees
Milestones
Pull Requests
关联的 Pull Requests 被合并后可能会关闭此 issue
Branches
Planed to start   -   Planed to end
-
Top level
Priority
参与者(2)
6732 thinkgem 1578914432
Java
1
https://gitee.com/thinkgem/jeesite4.git
git@gitee.com:thinkgem/jeesite4.git
thinkgem
jeesite4
JeeSite 4.2

Search