问题描述
我正在从LotusScript调用java getHTML(urlToRead)类(感谢您,Matt Holthe),该类使用CONST传递URL. Java代码位于Java脚本库"中.当我将常量urlToRead更改为变量时,java类不会读取该变量,并且我得到一个空响应.我是否需要使用内存中的文档,或者有更简单的方法吗?我需要获取返回的json值,因此除非使用内存中的文档,否则调用"将不起作用,而这是我想避免的.我开始认为我必须将整个代码转换为java,但是在LotusScript中更舒适.它正在Notes客户端中运行.
I am calling a a java getHTML( urlToRead ) class from LotusScript (thank you, Matt Holthe), which uses a CONST to pass the URL. The java code sits in a java "script-library". When I change the constant urlToRead to a variable, the java class does not read the variable and I get an empty response. 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. I am starting to think that I have to convert the entire code to java, but am more comfortable in LotusScript. This is running in 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
我尝试对myURLvar使用byVal,但这没什么区别.我如何获得Java代码以查看变量字符串?
I tried using byVal for myURLvar but that didn't make a difference. How do I get the java code to see the variable string?
推荐答案
这与使用常量或变量字符串作为getHtml()的参数无关.两者在您的示例中都能正常工作.
It is not about using a constant or variable string as parameter for getHtml(). Both work fine in your example.
我必须在Java中更改一行以使其运行("GET"而不是"PUT"):
I had to change one line in Java though to get it to run ("GET" instead of "PUT"):
conn.setRequestMethod("GET");
这是我的LotusScript代理的工作版本:
This is my working version of your LotusScript agent:
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
这篇关于将LotusScript参数传递给Java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!