问题描述: 在struts环境下,不能跳转到理想的url地址
比如登陆之后希望跳转到 http://w.xxx.com/system/home_enter.action
而实际上跳转到了 http://w.xxx.com/demo/system/home.action
找了很久问题的根源,最后发现原来是配置了redirect
<result name="success" type="redirect">/system/home_enter.action</result>
查了一下struts2 redirect源码,发现他默认会带上 request.getContextPatch();
想了很久,想从代码入手,最终无果。
最后只好选择了一种折中的办法。
去掉 type="redirect" 改成jsp页面
<result name="success" >/web/business/system/login/success.jsp</result>
然后在页面上通过javascript脚本进行人为的跳转。
<script>
function loadHome()
{
top.window.location="/system/home_enter.action";
}
</script>
</head>
<body class="login-layout light-login">
<div>正在加载资源...请稍后...</div>
<script>
loadHome();
</script>
</body>
这样最终解决了这个棘手的问题。
后面还发现一个类似的问题,但是有很多action用到了,不太好改,研究一下代码,实际上都是调用的模板类的enter方法,通过修改代码来指定调用enter方法来解决此问题。