NutzCN Logo
问答 前端跨域导致sessionid每次不一致的问题
发布于 1547天前 作者 qq_6c186ef5 3042 次浏览 复制 上一个帖子 下一个帖子
标签:

我用的是nutzboot2.3.6.v20190621的版本,由于用vue做了前后端分离之后,出现跨域,使用代理解决跨域后,后端每次请求得到的sessionid的不一样,这样就无法获取到session中存储的信息,在网上看了很多教程,大多都多说自己自定义过滤器(filter),然后在xml配置,需要设置很多请求信息,那nutzboot项目怎么实现呢?

 @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
            throws IOException, ServletException {
        HttpServletRequest httpServletRequest = (HttpServletRequest) request;
        HttpServletResponse httpServletResponse = (HttpServletResponse) response;
        // 判断是否是直接放行的请求
        if (!isFilterExcludeRequest(httpServletRequest)) {
            if (isCross) {
                httpServletResponse.setHeader("Access-Control-Allow-Origin", httpServletRequest.getHeader("origin"));
                httpServletResponse.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE");
                httpServletResponse.setHeader("Access-Control-Max-Age", "0");
                httpServletResponse.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");
                httpServletResponse.setHeader("Access-Control-Allow-Credentials", "true");
                httpServletResponse.setHeader("XDomainRequestAllowed", "1");
            }
        }
        chain.doFilter(request, response);
    }
2 回复

前后端分离要采用 JWT + Shiro
参考项目:
https://github.com/microapp-store/linjiashop

好的,我参考一下

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