简体   繁体   English

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

[英]to call html embedded applet by urlconnection

I have the following simple embedding applet html page:我有以下简单的嵌入小程序 html 页面:

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

If I call for this page (ie the address is " http://192.168.0.2/WelcomeApplet.html "), the applet is correctly shown in the browser.如果我调用这个页面(即地址是“ http://192.168.0.2/WelcomeApplet.html ”),小程序在浏览器中正确显示。

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:我应该只通过 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());     

Everything works fine the html parsed is the same as above, but the applet is not shown, the JVM reports: " WelcomeApplet.class not found "一切正常,解析的 html 与上面相同,但未显示小程序,JVM 报告:“ WelcomeApplet.class not found WelcomeApplet.class”

It looks like is not a security problem, but an implementation stuff (i guess).看起来不是安全问题,而是实现的东西(我猜)。

Any idea?任何想法?

Thanks谢谢

The code attribute should name a Java class, not a file. code属性应命名为 Java class,而不是文件。 (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. (JAR 文件由archive属性命名。)因此,假设它在默认命名空间中, code属性的值应该只是WelcomeApplet

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM