[英]passing LotusScript parameter to Java
I am calling aa java getHTML( urlToRead ) class from LotusScript (thank you, Matt Holthe), which uses a CONST to pass the URL.我正在从 LotusScript 调用 java getHTML( urlToRead ) 类(谢谢您,Matt Holthe),它使用 CONST 来传递 URL。 The java code sits in a java "script-library".
java代码位于java“脚本库”中。 When I change the constant urlToRead to a variable, the java class does not read the variable and I get an empty response.
当我将常量 urlToRead 更改为变量时,java 类不会读取该变量并且我得到一个空响应。 Do I need to use in-memory documents, or is there an easier way?
我需要使用内存中的文档,还是有更简单的方法? I need to get a return json value so a "call" does not work unless I'm using in-memory documents, which I am trying to avoid.
我需要获得一个返回 json 值,因此除非我正在使用内存中的文档,否则“调用”不起作用,这是我试图避免的。 I am starting to think that I have to convert the entire code to java, but am more comfortable in LotusScript.
我开始认为我必须将整个代码转换为 java,但在 LotusScript 中更舒服。 This is running in Notes Client.
这是在 Notes Client 中运行的。
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
I tried using byVal for myURLvar but that didn't make a difference.我尝试将 byVal 用于 myURLvar 但这并没有什么区别。 How do I get the java code to see the variable string?
如何获取java代码以查看变量字符串?
It is not about using a constant or variable string as parameter for getHtml().这不是关于使用常量或变量字符串作为 getHtml() 的参数。 Both work fine in your example.
在您的示例中两者都可以正常工作。
I had to change one line in Java though to get it to run ("GET" instead of "PUT"):我不得不在 Java 中更改一行以使其运行(“GET”而不是“PUT”):
conn.setRequestMethod("GET");
This is my working version of your LotusScript agent:这是我的 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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.