最近我向社群提出了一个问题:Can a Java Web Application access a Smart card reader on a remote work station?
根据我收到的答案,我决定编写一个Applet来尝试完成此操作。话虽这么说,我需要能够在GWT应用程序中运行Applet,以便我可以访问远程工作站上的读卡器,并使用从ID卡读取的信息授予用户访问应用程序某些部分的权限。根据我在this question的第4个答案中找到的建议,我将Applet编写为一个完全独立的Java项目,将其导出为.jar并使用jarsigner与我的证书签名。我能够验证jar并且它已正确签名。为了测试签名的jar / Applet的工作原理,我编写了一个简单的HTML页面,其中只包含applet标记,并将其放在htdocs文件夹中的Tomcat 7 Web服务器上。使用这个简单的页面,我可以访问远程工作站上的读卡器并阅读我需要的信息。
万岁。所以,继续我上面提到的第二个问题的建议,我试图使用jnlp使用以下GWT代码启动Applet:
HTML swipeCard = new HTML();
String appletHTML = "<applet code=\"main/java/com/prusa/swipeCardApplet/SwipeCardApplet.class\" height=\"200\" width=\"200\">"+
"<param name=\"jnlp_href\" value=\"swipeCardApplet.jnlp\">"+
"</applet>";
swipeCard.setHTML(appletHTML);
this._swipeCardLogin.add(swipeCard);
this._swipeCardLogin.setVisible(true);
我的jnlp文件看起来像:
<?xml version="1.0" encoding="UTF-8"?>
<jnlp href="swipeCardApplet.jnlp">
<information>
<title>Swipe Card Applet</title>
<vendor>pramericas.com</vendor>
</information>
<resources>
<j2se version="1.6+" />
<jar href="WEB-INF/lib/swipeCardApplet-1.0.0.jar" main="true" />
</resources>
<applet-desc
name="SwipeCardApplet"
main-class="main/java/com/prusa/swipeCardApplet/SwipeCardApplet.class"
width="200"
height="200">
</applet-desc>
<security>
<all-permissions />
</security>
</jnlp>
这是我的问题:在IE9中,当我将applet标签添加到我的GWT应用程序,然后导航到我将其包含在其中的页面时,applet会短暂显示为空白区域,IE警告会在底部闪烁的页面(太快阅读)然后页面刷新回到应用程序的主屏幕。
在Chrome中,我得到一个提示,说明我的java版本已经过时(它是),并且选项为&#34;此时运行&#34;。当我选择这次运行时,我会收到一个Java Authentication Required弹出窗口,要求输入用户名和密码来访问服务器上的应用程序。我输入凭据并单击“确定”。这导致applet显示&#34;错误。点击查看详情&#34;信息。这给了我以下内容:
Java Plug-in 1.6.0_21
Using JRE version 1.6.0_21-b07 Java HotSpot(TM) Client VM
User home directory = C:\Users\SWESTF01
----------------------------------------------------
c: clear console window
f: finalize objects on finalization queue
g: garbage collect
h: display this help message
l: dump classloader list
m: print memory usage
o: trigger logging
q: hide console
r: reload policy configuration
s: dump system and deployment properties
t: dump thread list
v: dump thread stack
x: clear classloader cache
0-5: set trace level to <n>
----------------------------------------------------
exception: Unable to load resource: https://dev.pramericas.com/hwslqc/WEB-INF/lib/swipeCardApplet-1.0.0.jar.
com.sun.deploy.net.FailedDownloadException: Unable to load resource: https://dev.pramericas.com/hwslqc/WEB-INF/lib/swipeCardApplet-1.0.0.jar
at com.sun.deploy.net.DownloadEngine.actionDownload(Unknown Source)
at com.sun.deploy.net.DownloadEngine.getCacheEntry(Unknown Source)
at com.sun.deploy.net.DownloadEngine.getCacheEntry(Unknown Source)
at com.sun.deploy.net.DownloadEngine.getResourceCacheEntry(Unknown Source)
at com.sun.deploy.net.DownloadEngine.getResourceCacheEntry(Unknown Source)
at com.sun.deploy.net.DownloadEngine.getResource(Unknown Source)
at com.sun.javaws.LaunchDownload$DownloadTask.call(Unknown Source)
at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by:
java.io.FileNotFoundException: https://dev.pramericas.com/hwslqc/WEB-INF/lib/swipeCardApplet-1.0.0.jar
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(Unknown Source)
at com.sun.deploy.net.HttpUtils.followRedirects(Unknown Source)
at com.sun.deploy.net.BasicHttpRequest.doRequest(Unknown Source)
at com.sun.deploy.net.BasicHttpRequest.doRequest(Unknown Source)
at com.sun.deploy.net.BasicHttpRequest.doGetRequest(Unknown Source)
at com.sun.deploy.net.DownloadEngine.actionDownload(Unknown Source)
at com.sun.deploy.net.DownloadEngine.getCacheEntry(Unknown Source)
at com.sun.deploy.net.DownloadEngine.getCacheEntry(Unknown Source)
at com.sun.deploy.net.DownloadEngine.getResourceCacheEntry(Unknown Source)
at com.sun.deploy.net.DownloadEngine.getResourceCacheEntry(Unknown Source)
at com.sun.deploy.net.DownloadEngine.getResource(Unknown Source)
at com.sun.javaws.LaunchDownload$DownloadTask.call(Unknown Source)
at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Exception: com.sun.deploy.net.FailedDownloadException: Unable to load resource: https://dev.pramericas.com/hwslqc/WEB-INF/lib/swipeCardApplet-1.0.0.jar
这只是我使用的路径的问题,还是我没有看到的其他东西?任何帮助或洞察我做错了什么将不胜感激。
一些资格:我使用带有Nexus存储库的Maven将我的.jar文件作为依赖项引入。依赖项的正确条目已添加到我的pom.xml文件中。
答案 0 :(得分:3)
exception: Unable to load resource:
https://dev.pramericas.com/hwslqc/WEB-INF/lib/swipeCardApplet-1.0.0.jar.
尝试使用浏览器直接获取该网址。我打赌你会看到“禁止”#39;或类似的。 lib
目录不是&#39; public&#39;目录,有必要将applet Jar移动到可访问的地方。