将 LotusScript 参数传递给 Java

passing LotusScript parameter to Java

我正在从 LotusScript 调用 java getHTML( urlToRead ) class(谢谢你,Matt Holthe),它使用 CONST 来传递 URL。 java 代码位于 java "script-library" 中。当我将常量 urlToRead 更改为变量时,java class 不读取该变量,我得到一个空响应。我需要使用内存中的文档,还是有更简单的方法?我需要得到一个 return json 值,所以 "call" 不起作用,除非我正在使用我试图避免的内存中文档。我开始认为我必须将整个代码转换为 java,但我更喜欢 LotusScript。这是 Notes 客户端中的 运行。

import java.io.*;
import java.net.*;

public class GetHTML {

    public String getHTML( String urlToRead) {
        URL url;
        HttpURLConnection conn; 
          BufferedReader rd; 
          String line; 
          String result = ""; 
          try {
             url = new URL(urlToRead);
             conn = (HttpURLConnection) url.openConnection();
             conn.setRequestMethod("PUT");
             rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
             while ((line = rd.readLine()) != null) {
                result += line;
             }
             rd.close();
          } catch (Exception e) {
             e.printStackTrace();
          }
        return result;
    }
}


Uselsx "*javacon"
Use "GetHTML"

Function getWebData( myURLvar As String) As String
    Const myURL = "http://mywebsite.com/testdb.nsf/testagent1"
    Dim js As JAVASESSION
    Dim getHTMLClass As JAVACLASS
    Dim getHTMLObject As JavaObject
    Dim html As String
    Set js = New JAVASESSION
    Set getHTMLClass = js.GetClass("GetHTML")
    Set getHTMLObject = getHTMLClass.CreateObject
' next line works because it uses CONSTANT
    html = getHTMLObject.getHTML( myURL )
    Msgbox "html: " + html
' next line does not work, uses variable
    html = getHTMLObject.getHTML( myURLvar )
    Msgbox "html: " + html
    getWebData = html   
End Function

我尝试将 byVal 用于我的URLvar,但这并没有什么不同。如何获取 java 代码以查看变量字符串?

它不是关于使用常量或变量字符串作为 getHtml() 的参数。在您的示例中两者都工作正常。

我不得不更改 Java 中的一行,但要将其更改为 运行("GET" 而不是 "PUT"):

        conn.setRequestMethod("GET");

这是我的 LotusScript 代理的工作版本:

UseLSX "*javacon"
Use "GetHTML"
Sub Initialize
    getWebData("http://www.spiegel.de/")
End Sub

Function getWebData( myURLvar As String) As String
    Const myURL = "http://www.spiegel.de/"
    Dim js As JAVASESSION
    Dim getHTMLClass As JAVACLASS
    Dim getHTMLObject As JavaObject
    Dim html As String
    Set js = New JAVASESSION
    Set getHTMLClass = js.GetClass("GetHTML")
    Set getHTMLObject = getHTMLClass.CreateObject
' next line works because it uses CONSTANT
    html = getHTMLObject.getHTML( myURL )
    MsgBox "html: " + html
' next line does not work, uses variable
    html = getHTMLObject.getHTML( myURLvar )
    MsgBox "html: " + html
    getWebData = html   
End Function