两个不同的项⽬间页⾯的跳转总结
  最近在项⽬中碰到⼀个棘⼿的问题,我们的项⽬是⽤两种语⾔写的,其两者之间会有⼀些跳转的交互。我所⾯临的问题就是通过Java项⽬调到ruby项⽬,然后还能由ruby项⽬跳转到Java项⽬。第⼀次做这个有点不知所措。最后⽤了解决⽅案(PS:项⽬中session共享问题已经解决了)。
  第⼀种解决办法是在前端做控制,window.location.herf进⾏连接的跳转。但是这个只能操作当前的window,因为我们的项⽬中是Java 页⾯作为⼀个iframe嵌套在ruby页⾯中。所以要变⽗页⾯的URL或者说就是整个页⾯的URL。总结⼀下:window.location.herf
  javascript中的location.href有很多种⽤法,主要如下。
1 self.location.href="/url" 当前页⾯打开URL页⾯
2 location.href="/url" 当前页⾯打开URL页⾯
3 windows.location.href="/url" 当前页⾯打开URL页⾯,前⾯三个⽤法相同。
4this.location.href="/url" 当前页⾯打开URL页⾯
5 parent.location.href="/url" 在⽗页⾯打开新页⾯
6 top.location.href="/url" 在顶层页⾯打开新页⾯
  如果页⾯中⾃定义了frame,那么可将parent self top换为⾃定义frame的名称,效果是在frame窗⼝打开url地址
  此外,window.location.href=window.location.href;和window.location.Reload()和都是刷新当前页⾯。区别在于是否有提交数据。当有提交数据时,window.location.Reload()会提⽰是否提交,window.location.href=window.location.href;则是向指定的url提交数据.
  最重要的是window.location.href 语句可以实现⼀个框架的页⾯在执⾏服务器端代码后刷新另⼀个框架的页⾯
  "window.location.href"、"location.href"是本页⾯跳转
  "parent.location.href"是上⼀层页⾯跳转
  "top.location.href"是最外层的页⾯跳转
  举例说明:
  如果A,B,C,D都是jsp,D是C的iframe,C是B的iframe,B是A的iframe,如果D中js这样写
  "window.location.href"、"location.href":D页⾯跳转
  "parent.location.href":C页⾯跳转
  "top.location.href":A页⾯跳转
记住我  如果D页⾯中有form的话,
  <form>: form提交后D页⾯跳转
  <form target="_blank">: form提交后弹出新页⾯
  <form target="_parent">: form提交后C页⾯跳转
  <form target="_top"> : form提交后A页⾯跳转
  关于页⾯刷新,D 页⾯中这样写:
  "load();": C页⾯刷新(当然,也可以使⽤⼦窗⼝的 opener 对象来获得⽗窗⼝的对象:
window.opener.load(); )
  "load();": A页⾯刷新
  第⼆种是在后端重定向到指定的URL,后端我们是使⽤springMVC,直接可以写URL来实现跳转,代码如下:
1 @RequestMapping("redirect/{agentPartyId}/{flag}")
2public String redirect(@PathVariable String agentPartyId, @PathVariable String flag){
3        PropertyPlaceholderConfigurer bean = Bean(PROPERTY_CONFIG_BEAN);
4        Properties pros = Properties();
5        String rubyServerUrl = Property(RUBY_SERVER_URL);
6        String url = rubyServerUrl + "/integration/t0?ext=/apply/"+agentPartyId+flag;
7        logger.info("apply redirect url={}", url);
8return "redirect:" + url;
9    }
  ⼤致想到的两种解决⽅案就是这样。