2015-05-04 94 views
0

以下是添加兩個數字的附加程序。IBM Mobilefirst 7.0 -Java適配器調用客戶端

我的服務器端編碼和客戶端編碼如下。
它拋出像

ReferenceError: com is not defined at (compiled_code):24

與Java適配器HTTP適配器工作的錯誤是強制性的。

Server.js和client.js如下

package com.mss; 
public class Calculator { 
public int addTwoIntegers(String first, String second){ 
    int c=Integer.parseInt(first)+Integer.parseInt(second); 
    return Integer.toString(c); 
} 

}

function addTwoIntegers(){ 
alert("hi"); 
var calcInstance = new com.mss.Calculator(); 
    return { 
    result : calcInstance.addTwoIntegers("1","2") 
    }; 

}

+0

Server.js?你可以解釋這是什麼server.js – sasi

+0

@Idan Adar不server.js它是服務器端Java代碼即Calculator.java。而Client.js的意思是客戶端的JavaScript。 –

+0

所以編輯你的問題是有道理的。 –

回答

1

To work with Java Adapter Http Adapter is mandatory

在假上述句子。在MFP 7.0中,您同時擁有JavaScript適配器和Java適配器。要使用Java適配器,您需要不需要以使用HTTP適配器。這沒有意義。它們是兩種不同類型的適配器。

閱讀以下教程:Server-side development

你已經採取了看看UsingJavaInAdapter適配器the Adapters sample?它證明了你正在嘗試做什麼。


你真的創建這樣一個com.mss Java類,並把它放在你的MFP項目的服務器\ java文件夾?

這個問題只是缺少信息。
Read the Java in JavaScript adapters tutorials


Java類

package com.sample.customcode; 

public class Calculator { 

    // Add two integers. 
    public static int addTwoIntegers(int first, int second){ 
     return first + second; 
    } 

    // Subtract two integers. 
    public int subtractTwoIntegers(int first, int second){ 
     return first - second; 
    } 
} 

適配器實現

function addTwoIntegers(a,b){ 
    return { 
     result: com.sample.customcode.Calculator.addTwoIntegers(a,b) 
    }; 
} 

function subtractTwoIntegers(a,b){ 
    var calcInstance = new com.sample.customcode.Calculator(); 
    return { 
     result : calcInstance.subtractTwoIntegers(a,b) 
    }; 
} 
+0

謝謝@Idan Adar –

相關問題