【问题标题】:IBM Mobilefirst 7.0 -Java Adapter Invocation Client SideIBM Mobilefirst 7.0 -Java 适配器调用客户端
【发布时间】:2015-05-04 18:44:50
【问题描述】:

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

我的服务器端编码和客户端编码如下。
它会抛出类似

的错误

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

必须使用 Java Adapter Http Adapter。

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

}

【问题讨论】:

  • Server.js?你能解释一下这个 server.js 是什么
  • @Idan Adar 不是 server.js,它是服务器端 java 代码,即 Calculator.java。 Client.js 表示客户端 javascript。
  • 所以编辑您的问题以使其有意义。
  • @Vinod 您不能直接从客户端调用 java 类。为此,您只需要适配器。无论您在 client.js 中编写什么,都必须在适配器中。
  • @sasi 你的意思是上面两段代码只能在服务器端。

标签: ibm-mobilefirst mobilefirst-adapters


【解决方案1】:

必须使用 Java Adapter Http Adapter

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

阅读以下教程:Server-side development

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


您是否真的创建了这样的com.mss Java 类并将其放置在 MFP 项目的 server\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)
    };
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-24
    • 1970-01-01
    相关资源
    最近更新 更多