由于两个系统间要进行页面跳转,并且需要前系统往后系统传值。于是,在前系统中,我用post的方式往后系统传值,在后系统用了request.getParameter("")来得到前系统传过来的值。
前系统代码:
...
<div id="yDoChinaLogin" style="float:right; width:70%;"">
<div class="rightTopDiv">
<c:choose>
<c:when test="${resultModel.loginMode eq
'incognito'}">
<div
style="height:30px;"></div>
</c:when>
<c:otherwise>
<div class="rightDiv" style="height:30px;">
<c:forEach var="menu" items="${resultModel.topMenuList}" step="1"
varStatus="menuStatus">
<div
class="rightSysDiv" style="float:left; width:170px;">
<span class="rightSysHref" title="${menu.url}"
id="${menu.systemId},${menu.safeLoginFlag}"
onclick="onSystemLogin(this.title,this.id)" ><u>${menu.systemName}</u>
</span>
</div>
</c:forEach>
</div>
</c:otherwise>
</c:choose>
</div>
...
<h:form styleId="LoginForm" method="POST" action="/hello/Welcome"
onsubmit="return false" target="_self">
<h:hidden
property="userContext.userId" value="${userContext.userId}" />
<h:hidden property="userContext.userName" value="${userContext.userName}"
/>
<h:hidden property="flag" />
<h:hidden
property="systemId" />
</h:form>
<script
type="text/javascript">
function onSystemLogin(actionPath, sysIdAndFlag)
{
var array = new Array();
array = sysIdAndFlag.split(",");
document.getElementById("systemId").value = array[0];
document.getElementById("flag").value = array[1];
var form =
document.forms["LoginForm"];
<h:msgSelfPageSet
key="ymc-commons.P.00004" />
form.action = actionPath;
form.target = "_bank";
form.submit();
}
后系统JSP端代码:
<%
String
flag = request.getParameter("flag");
if (flag != null) {
if (flag.equals("false")) {
%>
<jsp:forward
page="/login/Xb03TopLogin.do"/>
<%
} else {
%>
<jsp:forward page="/login/LoginTop.do"/>
<%
}
} else {
%>
<jsp:forward
page="/login/LoginTop.do"/>
<%
}
%>
在数据库中,定义url为http://localhost:8080/ymsm_mdm_war
一切编译OK通过,启动,点击链接,发现后系统接收不到前系统传过来的值,值都为null。很奇怪!
经查找,发现是传递的url末尾加”/“与不加”/“问题。
不加"/",系统会自动进行301的重定向,把url变成末尾加”/“的地址。而request.getParameter("")仅有一次生命周期,经过两次跳转后,前系统传的值失效了。此外,如直接发送 URL:http://msdn.microsoft.com/ie/ 比发送http://msdn.microsoft.com/ie速度将会更快,当然这种速度是感觉不到的,但优化应该“尽可能”,减少浪费的时间。
关于,301重定向问题,可参考http://blogs.msdn.com/ie/archive/2005/04/11/407189.aspx
本文探讨了URL末尾是否添加斜杠(/)对于页面跳转和参数传递的影响。当URL未以斜杠结尾时,系统可能会自动进行301重定向,导致请求参数在多次跳转后丢失。在实际应用中,这一问题可能导致后系统无法正确接收到前系统传递的值。解决此问题的关键在于理解HTTP的重定向机制以及request.getParameter()的生命周期。
6401

被折叠的 条评论
为什么被折叠?



