Java 未在HTML中加载小程序

Java 未在HTML中加载小程序,java,html,applet,clipboard,Java,Html,Applet,Clipboard,我试图用applet从我的网站的剪贴板粘贴图像。我发现我成功地做到了。他们展示了演示。我从这里下载了这个项目。我尝试在本地运行该文件,发现小程序没有按照演示加载。下面是html和小程序类 HTML <html> <head> <title>Clipboard image demo</title> <script type="text/javascript"> functi

我试图用applet从我的网站的剪贴板粘贴图像。我发现我成功地做到了。他们展示了演示。我从这里下载了这个项目。我尝试在本地运行该文件,发现小程序没有按照演示加载。下面是html和小程序类

HTML

<html>
    <head>
        <title>Clipboard image demo</title>

        <script type="text/javascript">
            function loadApplet() {
                // Deferred load to display text first
                document.getElementById("applet").innerHTML = '<object id="paste-image" classid="java:PasteImageApplet.class" type="application/x-java-applet" archive="tst.jar" width="1" height="1"></object>';
            }

            function getImage() {
                obj = document.getElementById('paste-image');
                postTo = "http://your-domain/path/to/shoot.php"; // Change this to your URL

                image = obj.getClipboardImageURL(postTo);

                if (image) {
                    url = "shots/" + image;

                    document.getElementById("target").src = url;
                    document.getElementById("url").value = document.getElementById("target").src; // to get full path, hack, I know ;)
                    document.getElementById("container").style.display = "";
                }
            }
        </script>

        <body onload="loadApplet();">

            <p>
                Copy some image data to your clipboard, accept the applet (it only accesses the clipboard) and click the button :-)
                <a href="http://lassebunk.dk/2009/07/19/using-the-clipboard-to-post-images/">See a blog post about this demo</a>
            </p>

            <p>
                <div id="applet"></div>
                <input type="button" value="Paste it!" onclick="getImage();">
            </p>

            <div id="container" style="display: none;">
                <input type="text" id="url" style="width: 700px;"><br />
                <iframe id="target" width="700" height="400"></iframe>
            </div>

    </body>
</html>

如果有人能就此提出建议,我将不胜感激

小程序类名中存在问题。我更改了类并加载了小程序。谢谢

“小程序未加载”哇,你能帮我解释一下吗?它有包含信息的危险。确保配置为显示小程序和JWS应用程序。如果默认级别没有输出,请提高该级别并重试。复制/粘贴任何错误或异常输出。
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.DataFlavor;
import java.awt.Toolkit;
import java.awt.Color;
import java.awt.image.BufferedImage;
import java.awt.image.ImageObserver;
import javax.swing.JApplet;
import javax.swing.JOptionPane;
import javax.swing.ImageIcon;
import java.io.ByteArrayOutputStream;
import com.sun.image.codec.jpeg.JPEGImageEncoder;
import com.sun.image.codec.jpeg.JPEGCodec;
import java.net.URL;
import java.net.URLConnection;
import java.io.InputStream;
import javax.swing.JLabel;

public class PasteImageApplet extends JApplet{

    Clipboard clipboard;
    Toolkit toolkit;
    JLabel lbl;

    public String getClipboardImageURL(String server){
        lbl.setText("pasting image");

        String url = "";
        try{
            DataFlavor dataFlavor = DataFlavor.imageFlavor;
            System.out.println(dataFlavor.getDefaultRepresentationClass());
            Object object  = null;

            try{
                object = clipboard.getContents(null).getTransferData(dataFlavor);
            }catch (Exception e){
                JOptionPane.showMessageDialog(null, "No image found.");
                return "";
            }

            BufferedImage img = (BufferedImage) object;

            BufferedImage bimg = null;
            int w = img.getWidth(null);
            int h = img.getHeight(null);
            bimg = new BufferedImage(w,h,BufferedImage.TYPE_INT_RGB);


            ImageIcon ii = new ImageIcon(img);
            ImageObserver is = ii.getImageObserver();

            bimg.getGraphics().setColor(new Color(255, 255, 255));
            bimg.getGraphics().fillRect(0, 0, w, h);
            bimg.getGraphics().drawImage(ii.getImage(), 0, 0, is);

            ByteArrayOutputStream stream = new ByteArrayOutputStream();
            JPEGImageEncoder jpeg = JPEGCodec.createJPEGEncoder(stream);
            jpeg.encode(bimg);                                               

            URL u = new URL(server);
            URLConnection con = u.openConnection();
            //String boundary = "-----------------------------7d637a1aa100de";
            con.setDoOutput(true);
            con.getOutputStream().write(stream.toByteArray());
            /*con.getOutputStream().write(((String)
                    "--"+boundary+"\r\n "+
                    "Content-Disposition: form-data; name=\"img\"; filename=\"filename\"\r\n"+
                    "Content-Type: image/jpeg\r\n "+
                    "Content-Transfer-Encoding: base64\r\n\r\n" +
                    Base64.encodeBytes(stream.toByteArray())).getBytes());*/
            con.connect();
            InputStream inputStream = con.getInputStream();
            byte [] urlBytes = new byte [inputStream.available()];
            inputStream.read(urlBytes);
            url = new String(urlBytes);
            System.out.print(url);
            lbl.setText("image pasted");
        } catch (Exception exc){
            lbl.setText("an error occurred: " + exc.getMessage());
            /*if (ShowExceptions.ShowExceptions)
                exc.printStackTrace();*/
        }
        return url;
    }

    public void init() {
        lbl = new JLabel("");
        lbl.setText("applet started");
        add(lbl);
        toolkit = Toolkit.getDefaultToolkit();
        clipboard = toolkit.getSystemClipboard();
    }
}