我用的是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);
}