2011-04-28 89 views
-1


在我的第一個JSP我正在坡平了一個jsp窗口。在這個彈出窗口中,我選擇了一些請求並通過servlet將它傳遞給另一個jsp。我的問題是,當我從彈出窗口向第二個jsp傳遞請求時,第二個jsp僅在相同的彈出窗口中顯示。我如何關閉彈出窗口並將請求傳遞給第二個jsp。在下面的代碼中,我在彈出的窗口中使用了重定向功能,但它不起作用。請幫我如何去了解它....如何通過servlet的動作重定向功能在javascript

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() 
} 
+0

能否請您闡述其不工作? – 2011-04-28 09:24:25

+0

我需要通過從彈出窗口下面的servlet行動,並關閉窗口,我怎麼可以這樣<%=的contextPath%>/AddInterviewPannel?IDS =「+ selectedIds – Akshatha 2011-04-28 09:29:08

+0

能否請您查看以下? – 2011-04-28 09:29:57

回答

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 
} 
+0

如何給參考彈出,並返回初始化?價值可以請你詳細說明它。因爲我正在學習jsp servlet現在我有n o想法如何去做。 – Akshatha 2011-04-29 11:35:31

+0

呼叫使用opener對象像opener.redirect(selectedIds)重定向(selectedIds)函數。這樣你可以在父窗口中將值傳遞給javascript。 – gnanz 2011-04-29 12:47:49

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> 

它的工作對我來說很好..比較你的代碼,找出原因。