简体   繁体   English

如何在JSP中将Java方法返回值传递给JavaScript函数?

[英]How to pass java method return value to JavaScript function in JSP?

I have the following line in my JSP file: 我的JSP文件中包含以下行:

<input type="button" name="btnNew" value="Új" class="button" onClick="clickSubmitButton('newRow'); isRowExists(<%tblMgr.isRowInDueCauseTable(request);%>)">

The isRowInDueCauseTable(request) method is returning a boolean value, but I'm not sure if I'm passing the boolean value to the javascript isRowExists function correctly, because I always get undefined, when I try to evaluate: isRowInDueCauseTable(request)方法返回一个布尔值,但是我不确定是否将布尔值正确传递给javascript isRowExists函数,因为在尝试求值时,我总是无法定义:

function isRowExists( isRowInDatabase ) {
        console.log(isRowInDatabase);
        if (isRowInDatabase == true) {
            alert('Already in database');
        }
    }

How can I pass the java methods return value to the JavaScript function in JSP? 如何将Java方法的返回值传递给JSP中的JavaScript函数?

尝试使用AJAX,您可以将文本(返回值)设置为request,然后在javascript函数中读取该文本。

The correct syntax needs the equal character( = ) to write a value. 正确的语法需要等号( = )来写入值。

See: 看到:

Incorrect way: 错误的方式:

<%tblMgr.isRowInDueCauseTable(request);%>

Correct way: 正确方法:

<%=tblMgr.isRowInDueCauseTable(request)%>

Then: 然后:

<input type="button" name="btnNew" value="Új" class="button" onClick="clickSubmitButton('newRow'); isRowExists(<%=tblMgr.isRowInDueCauseTable(request)%>)">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM