gpt4 book ai didi

java - 如何在CF中获取java类

转载 作者:行者123 更新时间:2023-11-30 11:11:01 25 4
gpt4 key购买 nike

我想从我的 coldfusion 文件中的 java 方法访问返回值。我已经加载了 coldfusion 文件中的所有 jar 文件并成功获得了 java 类对象。使用类对象,我想访问返回 Set 的 java 类方法;但我无法获得任何返回值。这是我的 Java 代码:

public Set getSession(String url) {       
result+="hello";
try {
DesiredCapabilities caps = new DesiredCapabilities();
caps.setJavascriptEnabled(true);
caps.setCapability("takesScreenshot", false);
caps.setCapability(
PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,
"E:\\TicketScraper\\phantomjs\\phantomjs.exe"
);
driver = new PhantomJSDriver(caps);
driver.get(url);
driver.findElement(By.id("login:loginName")).sendKeys("XXXX");
driver.findElement(By.id("login:password")).sendKeys("XXXX");
waitForJQueryProcessing(driver, 5);
driver.findElement(By.id("login:j_idt145")).click();
Thread.sleep(10000);
Set<org.openqa.selenium.Cookie> allCookies=driver.manage().getCookies();
for ( org.openqa.selenium.Cookie loadedCookie : allCookies) {
System.out.println(String.format("%s -> %s", loadedCookie.getName(),loadedCookie.getValue()));
}
} catch(Exception e) {
System.out.println(e);
}
return allCookies;
}

java代码运行Phantom JS驱动,登录上述代码中的URL,获取所有cookie。所有 cookie 都收集在 Set 变量中并从该方法返回。我想在 CF 代码中获取这个设置变量。

但是当我试图在 CF 中访问 java 方法的 Set 变量时,它没有返回任何值。相比之下,当我注释掉所有 Phantom JS 代码并仅返回一个 String 变量时,CF 就可以访问该字符串值。这是我的 CF 代码:

<cfscript>
paths = arrayNew(1);
paths[1] = expandPath("lib\apache-mime4j-0.6.jar");
paths[2] = expandPath("lib\bsh-1.3.0.jar");
paths[3] = expandPath("lib\cglib-nodep-2.1_3.jar");
paths[4] = expandPath("lib\commons-codec-1.9.jar");
paths[5] = expandPath("lib\commons-collections-3.2.1.jar");
paths[6] = expandPath("lib\commons-exec-1.1.jar");
paths[7] = expandPath("lib\commons-io-2.4.jar");
paths[8] = expandPath("lib\commons-jxpath-1.3.jar");
paths[9] = expandPath("lib\commons-lang3-3.3.2.jar");
paths[10] = expandPath("lib\commons-logging-1.1.3.jar");
paths[11] = expandPath("lib\Counsel_Cookies_Phantom.jar");
paths[12] = expandPath("lib\cssparser-0.9.14.jar");
paths[13] = expandPath("lib\gson-2.3.jar");
paths[14] = expandPath("lib\guava-18.0.jar");
paths[15] = expandPath("lib\hamcrest-core-1.3.jar");
paths[16] = expandPath("lib\hamcrest-library-1.3.jar");
paths[17] = expandPath("lib\htmlunit-2.15.jar");
paths[18] = expandPath("lib\htmlunit-core-js-2.15.jar");
paths[19] = expandPath("lib\httpclient-4.3.4.jar");
paths[20] = expandPath("lib\httpcore-4.3.2.jar");
paths[21] = expandPath("lib\httpmime-4.3.4.jar");
paths[22] = expandPath("lib\ini4j-0.5.2.jar");
paths[23] = expandPath("lib\jcommander-1.29.jar");
paths[24] = expandPath("lib\jetty-websocket-8.1.8.jar");
paths[25] = expandPath("lib\jna-3.4.0.jar");
paths[26] = expandPath("lib\jna-platform-3.4.0.jar");
paths[27] = expandPath("lib\junit-dep-4.11.jar");
paths[28] = expandPath("lib\netty-3.5.7.Final.jar");
paths[29] = expandPath("lib\nekohtml-1.9.21.jar");
paths[30] = expandPath("lib\operadriver-1.5.jar");
paths[31] = expandPath("lib\phantomjsdriver-1.1.0.jar");
paths[32] = expandPath("lib\protobuf-java-2.4.1.jar");
paths[33] = expandPath("lib\sac-1.3.jar");
paths[34] = expandPath("lib\selenium-java-2.44.0.jar");
paths[35] = expandPath("lib\selenium-java-2.44.0-srcs.jar");
paths[36] = expandPath("lib\serializer-2.7.1.jar");
paths[37] = expandPath("lib\testng-6.8.5.jar");
paths[38] = expandPath("lib\xalan-2.7.1.jar");
paths[39] = expandPath("lib\xercesImpl-2.11.0.jar");
paths[40] = expandPath("lib\xml-apis-1.4.01.jar");
paths[41] = expandPath("lib\Selenium_Cookies.jar");
paths[42] = expandPath("lib\selenium-server-2.0b2.jar");
//writeDump(paths);

//create the loader
loader = createObject("component", "javaloader.JavaLoader").init(paths,true);
//writeDump(loader);

excelObject = loader.create("counsel_cookies_phantom.Counsel_Cookies_Phantom");
//writeDump(excelObject);
//abort;
</cfscript>

<cfdump var=#excelObject.getSession("https://pacer.login.uscourts.gov/csologin/login.jsf")#/>
<cfabort>

请提供有关如何在 CF 中访问 Phantom JS 值的建议。

最佳答案

假设您的 Set 是一个 java.util.Set,然后调用 toArray() 将为您提供一个在 CF 中可轻松访问的数组.

例如

<cfscript>
s = createObject("java", "java.util.HashSet").init();
s.add("foo");
s.add("bar");
s.add("bob");

arr = s.toArray();

writeDump(arr);
</cfscript>

Run this on TryCF.com

关于java - 如何在CF中获取java类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27561662/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com