如何在javascript中的重定向函数中传递servlet动作

时间:2011-04-28 09:06:49

标签: java javascript jsp servlets


在我的第一个jsp中,我正在弹出一个jsp窗口。在这个弹出窗口中,我选择了一些请求并通过servlet将其传递给另一个jsp。我的问题是当我将请求从弹出窗口传递给第二个jsp时,第二个jsp仅显示在同一个弹出窗口中。如何关闭弹出窗口并将请求传递给第二个jsp。在下面的代码中,我在弹出窗口中使用了重定向功能,但它无法正常工作。请帮我怎么做......

function UpdatePannel()
{
var selectedIds;
var count=0;
for (i=0; i<document.frm1.check1.length; i++)
{
if (document.frm1.check1[i].checked==true)
{
if(count==0){
selectedIds=document.frm1.check1[i].value; 
count=count+1; 
}
else
selectedIds=selectedIds+","+document.frm1.check1[i].value;
}
}
alert(selectedIds);  

//document.frm1.action="<%=contextPath%>/AddInterviewPannel?ids="+selectedIds;
//window.close()
     //   document.frm1.submit();

     redirect();
} 

function redirect()
{
opener.location.href="<%=contextPath%>/AddInterviewPannel?ids="+selectedIds;
window.close()
}

2 个答案:

答案 0 :(得分:1)

popup.html

<html> 
<head> 
</head> 
<body> 
<a href="#" onclick="window.opener.location.href='new.htm';">change parent</a> 
</body> 
</html>

parent.html

<html> 
<head> 
</head> 
<body> 
<a href="#" onclick="window.open('popup.html','kid','resizable=no,scrollbars=no,width=250,height=148,toolbar=no');">click</a> 
</body> 
</html>

它对我来说很好。比较你的代码并找出原因。

答案 1 :(得分:1)

将此javascript放在父窗口中。在父函数中调用此javascript函数redirect,参数需要像redirect(selectedIds)

那样传递

更新javascript函数重定向以接受参数

function redirect(selectedIds){
    opener.location.href="<%=contextPath%>/AddInterviewPannel?ids="+selectedIds;
    popupobj.close() // popupobj => have the reference to popup , initialize this with return value of window.open
}