由于项目是对老系统进行技术升级改造,需要很长一段时间才会改造完毕,在改造过程为了不影响客户使用,所以决定在新系统不断改造的过程中,依然可以访问老系统,就是将老系统的页面嵌套见新系统,在嵌套的过程中遇到如下问题:当新系统拿着用户信息登陆进老系统,老系统的页面成功嵌套进新系统,但是在此点击老系统里面的功能时,弹出老系统的登陆界面。
1.认为是两个系统写在cookie中的jessionId冲突了,随即修改一个系统的jessionId名称,但是问题依然存在。
2.在新系统访问旧系统的时候,在旧系统添加过滤器代码带上Access-Control-Allow-Origin头信息解决跨域问题。
后台添加过滤器
public void doFilter(ServletRequest servletRequest,
ServletResponse servletResponse, FilterChain filterChain)
throws IOException, ServletException {
// TODO Auto-generated method stub
//log.info("Adding Access Control Response Headers");
HttpServletResponse response = (HttpServletResponse) servletResponse;
// String origin =((HttpServletRequest) servletRequest).getHeader("Origin");
String origin ="http://localhost:8080";
response.setHeader("Access-Control-Allow-Origin", origin);
response.setHeader("Access-Control-Allow-Credentials", "true");
response.setHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, HEAD, OPTIONS");
response.setHeader("Access-Control-Allow-Headers",
"X-Requested-With, Origin, Accept, X-Request-With, Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers, Date, Server, Cache-Control, withCredentials, AccessToken, User-Agent");
response.setHeader("P3P", "CP=\"ALL IND DSP COR ADM CONo CUR CUSo IVAo IVDo PSA PSD TAI TELo OUR SAMo CNT COM INT NAV ONL PHY PRE PUR UNI\"");
HttpServletRequest request = (HttpServletRequest) servletRequest;
if ( request.getMethod().equals( "OPTIONS" ) ) {
(response).setStatus(HttpServletResponse.SC_OK);
return;
}
filterChain.doFilter(request, response);
}