2013-08-28 46 views
1

我有一个问题。如何使用showModalDialog传递参数

我在JSP文件中写入以下内容。

<s:url id="printURL" action="actMod" method="printout"> 
    <s:param name="txt_ActEdit_accid"><s:property value="%{txt_ActEdit_accid}" /></s:param> 
    <s:param name="txt_ActEdit_accffname"><s:property value="%{txt_ActEdit_accffname}" /></s:param> 
    <s:set var="loginPassword"><%=OpeCommon.LOGIN_PASSWORD %></s:set> 
    <s:param name="%{#loginPassword}"><%=OpeCommon.encriptPassword(p_userID, p_passCode)%></s:param> 
</s:url> 
<s:submit name="btn_ActList_print" cssClass="dispLvl3 mediumbutton" value="%{getFieldName('S05AccountEdit.print_button')}" 
onclick="javascript:popUp('%{printURL}','elastic',500,500);return false;"/> 

我在js文件中写入以下内容。

var newWin = null; 

function popUp(strURL, strType, strHeight, strWidth) { 
    if (newWin != null && !newWin.closed) 
    newWin.close(); 
    var strOptions=""; 
    if (strType=="console") 
    strOptions="resizable,height="+ 
     strHeight+",width="+strWidth; 
    if (strType=="fixed") 
    strOptions="status,height="+ 
     strHeight+",width="+strWidth; 
    if (strType=="elastic") 
    strOptions="toolbar,menubar,scrollbars,"+ 
     "resizable,location,height="+ 
     strHeight+",width="+strWidth; 
    newWin = window.open(strURL, 'newWin', strOptions); 
    newWin.focus(); 
} 

它知道所有参数值,但是当我更改JavaScript函数名称和脚本编码时,它不起作用。我的意思是它只知道第一个参数值(txt_ActEdit_accid)。

<s:submit name="btn_ActList_print" cssClass="dispLvl3 mediumbutton" value="%{getFieldName('S05AccountEdit.print_button')}" 
onclick="javascript:printWindow('%{printURL}','',500,500);return false;"/> 
function printWindow(x_URL, x_ARG, x_WIDTH, x_HEIGHT) 
{ 
    var x_OPT = "dialogHeight: "+x_HEIGHT+"px; " 
    +"dialogWidth: "+x_WIDTH+"px; " 
    +"edge: Raised; center: Yes; resizable: Yes; status: Yes;"; 
    window.showModalDialog(x_URL, x_ARG, x_OPT); 
} 

如何解决这个问题?

+0

看起来像'x_ARG ==='''。你可以用'showModalDialog()'的'arguments'参数将一个参数传递给对话。如果您需要多个值,则需要创建一个数组或对象来传递更多值。 – Teemu

+0

如果我使用数组或对象从X_ARG传递值,如何从java操作方法调用该参数值? –

+0

不幸的是,Java超出了我的理解。 – Teemu

回答

0

现在,您有s:url标记的问题。 Struts标签通常是转义value的标签。但它阻止了JavaScript正常工作。您需要将escapeAmp="false"添加到s:url标记以获取其他参数。

+0

我还有一个问题。今天,我注意到参数(例如:'')不会在弹出页面中正确显示日文字体。我在Popup Page(JSP)中编写了以下代码。 <%@ page language =“java”contentType =“text/html; charset = UTF-8”pageEncoding =“UTF-8”% ' 其他日语句子显示正确,但来自JScript Popup的参数无法正确显示。请问您能解释一下吗?提前致谢 !!! –

+0

参数不使用页面编码进行编码。您可以手动对其进行编码,也可以将服务器配置为您最喜欢的编码。 –

+0

请给我这个问题的一些建议; [链接] http://stackoverflow.com/questions/19086190/request-getparameter-does-not-display-properly-character-encoding-in-java-serv –