2017-11-08 18:13

@JFinal 这个可能和安卓手机微信的相关机制有关系:

前端用的是 react 单页面开发的,假如点击“绑定账号”菜单,其地址是 http://abc.com/weixinFront/bind.parents,
/weixinFront/bind.parents 是前端的路由地址,点击后到tomcat 找不到对应的资源应该跳转到已配置好的 404 页面才对,苹果手机点击后 tomcat 的 404 配置生效,安卓手机点击后 tomcat 的 404 配置不生效,解决方法是:在 handler 中拦截包含前端路由地址的请求,强制让其跳转到 404 页面。

switch (s){
case "/weixinFront/class.parents/answer":
case "/weixinFront/class.parents/ask":
case "/weixinFront/class.parents/collaborate":
case "/weixinFront/work.parents/complete":
case "/weixinFront/work.parents/result":
case "/weixinFront/work.parents/use_time":
case "/weixinFront/bind.parents":
case "/weixinFront/bind_remove.parents":
log.info("访问路径 --> "+s);
try {
log.info("转发到 /weixinFront/index.html 页面...");
httpServletResponse.sendRedirect("/weixinFront/index.html");
}
catch (IOException e) {
log.error("转发到 /weixinFront/index.html 页面失败!",e);
e.printStackTrace();
}
break;

default:
log.info("default 访问路径 --> "+s);
break;
}

只要到了 index.html (404) 页面,前端路由就能控制其跳转到不同的地方,显示具体的页面,问题解决。