2015-02-24 72 views
0

我無法在JavaScript中調用Java函數。我想,當我將像Var這樣的參數傳遞給字符串方法時,我做錯了。請給我你的建議。如何將字符串參數傳遞給JavaScript函數中的Java方法

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方法() 公共字符串getFreeDomTerminationFee(字符串AREACODE,字符串交換,字符串連接,字符串後綴)拋出異常 {

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; 
} 

回答

1

的JavaScript運行在瀏覽器中的Java在服務器上運行。您需要通過JavaScript進行Ajax調用才能調用Java應用程序。您不能直接從JavaScript直接「調用」Java方法。

相關問題