我需要从javafx Webengine中的文件myFunctions.js执行脚本,并使用resttemplate将信息发送到服务器:
public void onDeviceStatusChanged(DeviceStatusEvent deviceStatusEvent) {
String uri = defaultPage + "my/" + "devices/status";
if (deviceStatusEvent.getDevStat().getDev() == 0) {
webEngine.executeScript("billAcceptorStatus(" + deviceStatusEvent.getDevStat().getStatus() + ")");
}
if (deviceStatusEvent.getDevStat().getDev() == 1) {
webEngine.executeScript("posPrinterStatus(" + deviceStatusEvent.getDevStat().getStatus() + ")");
}
if (deviceStatusEvent.getDevStat().getDev() == 2) {
webEngine.executeScript("cardReaderStatus(" + deviceStatusEvent.getDevStat().getStatus() + ")");
}
if (deviceStatusEvent.getDevStat().getDev() == 4) {
webEngine.executeScript("pinPadStatus(" + deviceStatusEvent.getDevStat().getStatus() + ")");
}
try {
if (deviceStatusEvent.getDevStat().getDev() == 0) {
if (deviceStatusEvent.getDevStat().getStatus() == 2) {
HttpEntity request = new HttpEntity<>(defaultHeaders.getMap());
String string = restTemplate.postForObject(defaultPage + "/my/" + "devices/ink", request, String.class);
}
}
HttpEntity<SimpleDevStat> request = new HttpEntity<>(deviceStatusEvent.getDevStat(), defaultHeaders.getMap());
restTemplate.postForLocation(uri, request);
log.debug("Posted : " + deviceStatusEvent.getDevStat());
webEngine.executeScript("networkStatus(true)");
} catch (Exception e) {
webEngine.executeScript("networkStatus(false)");
e.printStackTrace();
}
}
如果未将myFunctions.js加载到webengine,则webengine.executeScript()无效并且代码会停止此行。我需要检查webengine中是否存在myFunctions.js。如何检查webengine中的js文件?