0

我需要一些关于js从 javascript 调用函数的帮助。

我有一个 servlet 可以检查协议号是否null存在。如果协议号不是null那么它将在jsp中显示一个消息框。

Servlet 代码是 -

String agrno = request.getParameter("agrno");
System.out.println("agrno in checkcash =" + agrno);
sql = "select agrno from ColdStorage.RecieptMaster where agrno = ?";
prest = (PreparedStatement) conn.prepareStatement(sql);
prest.setString(1, agrno);
String agrid = "";
rs = prest.executeQuery();
while(rs.next())
{
    agrid = rs.getString("agrno");
    System.out.println("agrid = "+agrid);
}

if(agrid != null)
{
    // javascript call should be here.
}

和javascript代码是:

Ext.widget('button', {
    renderTo: Ext.getBody()
    , text: 'Show Message'
    , handler: function () {
        Ext.Msg.show({
            //title: '',
            msg: 'Cash Receipt for specified Agreement number already exist, do you want to regenerate it? ',
            buttonText: { yes: "YES", no: "NO"},
            buttons: Ext.MessageBox.YESNO
        });
    }
});
4

1 回答 1

0

您可以将agrid值呈现给 HTML 代码(到hidden输入或data-某些标记的属性),然后在页面加载时运行脚本,该脚本会检查该参数并相应地显示消息。例子:

HTML/JSP:

<input id="agrid" type="hidden" value="${agrid}">

JavaScript (jQuery):

$(document).ready(function() {
   var argid = $('#agrid').val(); // 
   if (!agrid) {
      // Show the message box
   }
});
于 2013-05-29T07:44:33.473 回答