我们正在使用Oracle ADF开发的Web应用程序。
1)在文档页面下载和打开文件夹按钮中,我们使用小程序将文件下载到客户端计算机中的某个位置并打开文件夹
2)从文档页面下载并打开文件按钮,我们正在使用小程序将文件下载到客户端计算机中的某个位置并打开这些文件
3)从文档页面打开文件夹按钮,如果存在,将打开相应的文件夹。
以上3点已经存在并且运作良好。
现在,因为将从浏览器中删除插件支持。我们正在寻找替代解决方案。
任何建议都会对我们有所帮助..请告知
此致 阿伦
答案 0 :(得分:0)
要替换java aplet,您可以使用实现restful接口的本地服务。
使用对jnlp
文件的简单GET请求启动本地服务。例如,http://example.com/localservice.jnlp这将下载,安装和运行本地服务(对它的要求是applet - 必须签名)。成功启动本地服务后,Web应用程序就可以提交和读取数据,就像使用任何Web服务器一样。
但是,应该记住浏览器不允许交叉查询。因此,应返回本地服务的CORS header
或其侦听的地址(127.0.0.1
)应该是应用程序域的一部分(这由具有A
记录的子域完成对于127.0.0.1
,例如localhost.example.com
)
这是一个转换示例(非常粗糙) 这是本地服务,它在端口8888上侦听传入的HTTP查询并返回JSON响应。
public class LocalService {
public LocalService() {
}
public static void main(String[] args) throws IOException {
HttpServer server = HttpServer.create(new InetSocketAddress("localhost", 8888), 0);
server.setExecutor(Executors.newSingleThreadExecutor());
server.createContext("/", httpExchange -> {
StringBuilder builder = new StringBuilder();
int read;
byte buffer[] = new byte[1024];
InputStream is = httpExchange.getRequestBody();
while ((read = is.read(buffer)) != -1) {
builder.append(new String(buffer, 0, read));
}
is.close();
String response = String.format("{\"request\": \"%s\"}", builder.toString());
Headers headers = httpExchange.getResponseHeaders();
headers.add("Content-Type", "application/json");
headers.add("Access-Control-Allow-Origin", "*");
httpExchange.sendResponseHeaders(200, response.length());
OutputStream os = httpExchange.getResponseBody();
os.write(response.getBytes());
os.flush();
os.close();
});
server.start();
}
}
这是用于启动服务的JNLP文件。
<?xml version="1.0" encoding="UTF-8"?>
<jnlp spec="1.0+" codebase="" href="">
<information>
<title>Local Service</title>
</information>
<resources>
<!-- Application Resources -->
<jar href="http://example.com/localservice.jar" main="true" />
</resources>
<security>
<all-permissions/>
</security>
<application-desc name="Local Service" main-class="LocalService">
</application-desc>
<update check="background"/>
</jnlp>
这是一个自动或手动启动服务并从中发送和接收数据的HTML页面
<!DOCTYPE html>
<html>
<head>
<title>Local Service</title>
<script
src="https://code.jquery.com/jquery-3.3.1.min.js"
integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
crossorigin="anonymous"></script>
<script>
$(function() {
$('#send').click(function() {
$.ajax({
method: 'POST',
url: 'http://localhost:8888', // or localhost.example.com:8888
data: $('#data').val(),
success: function(data, textStatus, jqXHR) {
alert(data.request);
},
error: function(jqXHR, textStatus, errorThrown) {
alert(errorThrown);
}
});
});
});
</script>
</head>
<body>
<h1>Local Service</h1>
<!-- auto load local service -->
<iframe style="display: none;" src="localservice.jnlp"></iframe>
<a href="localservice.jnlp">Run Local Service Manually</a>
<div style="margin-top: 50px;">
<input id="data"/>
<button id="send">Send</button>
</div>
</body>
</html>