我无法在JavaScript中调用Java函数。我想,当我将Var这样的参数传递给字符串方法时,我做错了。请给我你的建议。
function calculateTotalAmount()
{
var formFldAreaCode = eval("document.AccountsSummaryListing.<%=SWPAppConstants.AREA_CODE%>");
alert("area code "+formFldAreaCode.value);
var formFldExchange = eval("document.AccountsSummaryListing.<%=SWPAppConstants.EXCHANGE%>");
alert("formFldExchange "+formFldExchange.value);
var formFldConnector = eval("document.AccountsSummaryListing.<%=SWPAppConstants.CONNECTOR%>");
alert("formFldConnector code "+formFldConnector.value);
var formFldConnectorSuffix = eval("document.AccountsSummaryListing.<%=SWPAppConstants.CONNECTOR_SUFFIX%>");
alert("formFldConnectorSuffix code "+formFldConnectorSuffix.value);
//getting error here
var installmentAmount = '<%=smPage.getFreeDomTerminationFee(formFldAreaCode.value,formFldExchange.value,"'formFldConnector.value,formFldConnectorSuffix.value)%>';
alert("Alert "+installmentAmount);
}
Java方法() public String getFreeDomTerminationFee(String areaCode,String exchange,String connector,String suffix)抛出异常 {
System.out.println("Ramesh areaCode "+areaCode);
m_logMgr.logMessage(LogManager.LOG_EVENT,"AccountsSummaryListing "+areaCode+"exchange "+exchange+"connector "+connector+" suffix "+suffix, m_FTCuserContext.getCurrentUserId(), 10, 1);
/* Connection origConn = m_bussContext.getConnection();
Connection sosConn = getSOSConnection();
m_bussContext.setConnection(sosConn);*/
FreedomPlnManager frdmPlnMngr = new FreedomPlnManager(this.m_bussContext, this.m_FTCuserContext);
String installmentAmount = "0";
FreedomPlnDS freedomPlnDS = frdmPlnMngr.getFreedomPlanDetails(areaCode,exchange ,connector ,suffix);
//m_bussContext.setConnection(origConn);
if(freedomPlnDS!= null){
installmentAmount = freedomPlnDS.getInstallmentAmount();
}
m_logMgr.logMessage(LogManager.LOG_EVENT,"AccountsSummaryListing:etfValue = "+installmentAmount, m_FTCuserContext.getCurrentUserId(), 10, 1);
return installmentAmount;
}
答案 0 :(得分:1)
JavaScript在浏览器中运行,Java在服务器上运行。您需要从JavaScript进行Ajax调用以调用Java应用程序。你不能简单地“打电话”#34;直接来自JavaScript的Java方法。