通过urlconnection调用html嵌入的小程序

发布于 2024-11-18 11:26:55 字数 1223 浏览 1 评论 0原文

我有以下简单的嵌入小程序 html 页面:

<html>
    <applet code="WelcomeApplet.class" archive="WelcomeApplet.jar" width=300 height=30>
    </applet>
</html>

如果我调用此页面(即地址是“http://192.168.0.2/WelcomeApplet.html”), 小程序正确显示在浏览器中。

我应该仅通过 servlet 调用此页面,因为不应显示 url 页面,因此在 doGet servlet 方法中插入以下代码:

URL url = new URL("http://192.168.0.2/WelcomeApplet.html");    
URLConnection conn = url.openConnection();     
conn.setRequestProperty("Content-Language", "en-US");    
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");    
conn.setDoInput(true);    
conn.setUseCaches(false);    
conn.setAllowUserInteraction(true);    

BufferedInputStream buffer = new BufferedInputStream(conn.getInputStream());    
StringBuilder builder = new StringBuilder();    
int byteRead;    
while ((byteRead = buffer.read()) != -1)    
    builder.append((char) byteRead);    
buffer.close();    
out.write(builder.toString());     

一切正常,解析的 html 与上面相同,但是小程序未显示,JVM 报告:“WelcomeApplet.class not found

看起来不是安全问题,而是实现问题(我猜)。

有什么想法吗?

谢谢

I have the following simple embedding applet html page:

<html>
    <applet code="WelcomeApplet.class" archive="WelcomeApplet.jar" width=300 height=30>
    </applet>
</html>

If I call for this page (i.e. the address is "http://192.168.0.2/WelcomeApplet.html"),
the applet is correctly shown in the browser.

I should call this page only by a servlet because the url page should not be shown, so in the doGet servlet method the following code is inserted:

URL url = new URL("http://192.168.0.2/WelcomeApplet.html");    
URLConnection conn = url.openConnection();     
conn.setRequestProperty("Content-Language", "en-US");    
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");    
conn.setDoInput(true);    
conn.setUseCaches(false);    
conn.setAllowUserInteraction(true);    

BufferedInputStream buffer = new BufferedInputStream(conn.getInputStream());    
StringBuilder builder = new StringBuilder();    
int byteRead;    
while ((byteRead = buffer.read()) != -1)    
    builder.append((char) byteRead);    
buffer.close();    
out.write(builder.toString());     

Everything works fine the html parsed is the same as above, but the applet is not shown, the JVM reports : "WelcomeApplet.class not found"

It looks like is not a security problem, but an implementation stuff (i guess).

Any idea?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

久而酒知 2024-11-25 11:26:55

code 属性应该命名一个 Java 类,而不是一个文件。 (JAR 文件由 archive 属性命名。)因此,code 属性的值应该是 WelcomeApplet,假设它位于默认命名空间。

The code attribute should name a Java class, not a file. (The JAR file is named by the archive attribute.) Thus, the value of the code attribute should be just WelcomeApplet, assuming it is in the default namespace.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文