IBM Mobilefirst 7.0 -Java 适配器调用客户端

IBM Mobilefirst 7.0 -Java Adapter Invocation Client Side

下面是两个数相加的加法程序

我的Server端编码和Client端编码如下。
它会抛出类似

的错误

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

}

To work with Java Adapter Http Adapter is mandatory

以上句子错误。在 MFP 7.0 中,您同时拥有 JavaScript 适配器和 Java 适配器。要使用 Java 适配器,您 不需要 使用 HTTP 适配器。那没有意义。它们是两种不同类型的适配器。

阅读以下教程:Server-side development

您看过 the Adapters sample 中的 UsingJavaInAdapter 适配器了吗?它准确地演示了您要做什么。


您是否真的创建了这样一个 com.mss Java class 并将其放在您的 MFP 项目的 server\java 文件夹中?

问题只是缺少信息。
Read the Java in JavaScript adapters tutorials.


Java class

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