通过urlconnection调用html嵌入的小程序
我有以下简单的嵌入小程序 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
code
属性应该命名一个 Java 类,而不是一个文件。 (JAR 文件由archive
属性命名。)因此,code
属性的值应该是WelcomeApplet
,假设它位于默认命名空间。The
code
attribute should name a Java class, not a file. (The JAR file is named by thearchive
attribute.) Thus, the value of thecode
attribute should be justWelcomeApplet
, assuming it is in the default namespace.