Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/344.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Web论坛小程序在小程序查看器中工作,但在浏览器中不工作_Java_Html_File_Security_Applet - Fatal编程技术网

Java Web论坛小程序在小程序查看器中工作,但在浏览器中不工作

Java Web论坛小程序在小程序查看器中工作,但在浏览器中不工作,java,html,file,security,applet,Java,Html,File,Security,Applet,我在一个嵌入式小程序上遇到了问题,我已经工作了一段时间了。小程序的jar已签名,所有权限都已授予,并且在小程序查看器中运行良好。当加载到浏览器中时,只有一个带有错误标志的空白框,我的小程序应该在这个框中。单击时返回“java.lang.invocationtargetexception”。我使用基本的HTML格式嵌入小程序。 下面是我用来显示它的HTML代码: <html> <body background="BG.png"> <a href="index.htm

我在一个嵌入式小程序上遇到了问题,我已经工作了一段时间了。小程序的jar已签名,所有权限都已授予,并且在小程序查看器中运行良好。当加载到浏览器中时,只有一个带有错误标志的空白框,我的小程序应该在这个框中。单击时返回“java.lang.invocationtargetexception”。我使用基本的HTML格式嵌入小程序。 下面是我用来显示它的HTML代码:

<html>
<body background="BG.png">

<a href="index.html">Back to the index</a>

<center><h1>Web Forum</h1></center>
<center><table border = "0">

<tr>
<td><center><h3>Forums</h3></center></td>
<td width = 25></td>
<td width = 225><center><h3>Chatbox</h3></center></td>
</tr>

<tr>
<td><center><applet
code=Topics.class
archive=Topics.jar
width=750
height=1000 ><PARAM name="permissions" value="sandbox"></PARAM>
</applet></center></td>

<td width = 25></td>

<td width = 225 bgcolor = #00FF00><center><h3>Coming Soon</h3></center></td>
</tr>

</table></center>
</Body>
</Html> 
以下是已签名jar的清单:

Manifest-Version: 1.0

Name: .classpath
SHA-256-Digest: IhqMeyTH+t/Wtxr+NP6B1f5GapLwQ67HJhYQ7UM+kA0=

Name: .project
SHA-256-Digest: Lw9C+yAb3p1vC6m2pwcjhv8TB1ET8xOYjM2sFlgIjIw=

Permissions: all-permissions
Codebase: http://25.2.202.42/
我看不出代码本身会导致错误的原因,但这里只是以防万一:

import java.awt.*;
import java.awt.event.*;

import javax.swing.*;

import java.applet.*;
import java.io.*;


@SuppressWarnings("serial")
public class Topics extends Applet {

String name;
String topics;
String paragraphs;
//reading file for existing posts
String fileread = "Topics.txt";
static String line = null;
{
try {
    FileReader fileReader = 
        new FileReader(fileread);

    BufferedReader bufferedReader = 
        new BufferedReader(fileReader);

    while((line = bufferedReader.readLine()) != null) {
        System.out.println(line);
    }   

    bufferedReader.close();         
}
catch(FileNotFoundException ex) {
    System.out.println(
        "Unable to open file '" + 
        fileread + "'");                
}
catch(IOException ex1) {
    System.out.println(
        "Error reading file '" 
        + fileread + "'");                  

}
}
static String display = line;

JPanel topicPanel;
JLabel title, username, topic, paragraph, topicsTitle, dtopicsTitle;
JTextField nameField, topicField;
JButton submitButton, topicrefreshButton;
JTextArea paragraphArea, topicArea;


public void init() {
    final JPanel topicGUI = new JPanel();
    topicGUI.setLayout(null);

    setBackground(Color.GREEN);

    setVisible(true);

    // JLabels

    JLabel title = new JLabel("                                                                           Make A Post                                                                           ");
    title.setSize(150, 25);
    title.setFont(new Font("Serif", Font.PLAIN, 25));
    title.setHorizontalAlignment(0);
    add(title);


    JLabel username = new JLabel("Username: ");
    username.setSize(70, 15);
    username.setHorizontalAlignment(0);
    add(username);

    // JTextField

    nameField = new JTextField(8);
    nameField.setSize(150, 18);
    add(nameField);

    // JLabel

    JLabel topic = new JLabel("Topic: ");
    topic.setSize(40, 15);
    topic.setHorizontalAlignment(0);
    add(topic);

    // JTextField

    topicField = new JTextField(8);
    topicField.setSize(180, 18);
    add(topicField);


    //JLabel

    JLabel paragraph = new JLabel("                                                                                          Paragraph:                                                                                          ");
    paragraph.setSize(70, 15);
    paragraph.setHorizontalAlignment(0);
    add(paragraph);

    // JTextAreas

    paragraphArea = new JTextArea(8, 5);
    paragraphArea.setSize(700, 100);
    paragraphArea.setLineWrap(true);
    paragraphArea.setEditable(true);
    add(paragraphArea);


    // JButton

    JButton submitButton = new JButton("SUBMIT");
    submitButton.setSize(100, 30);
    submitButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {

            name = nameField.getText();
            topics = topicField.getText();
            paragraphs = paragraphArea.getText();



            display ="\n" + "\t" + name + " - " + "\n" + "\t" + topics + " : " + "\n" + paragraphs + display + "\n";

            topicField.setText("");
            paragraphArea.setText("");

            //writing new info to file
            String fileName = "Topics.txt";

            try {
                FileWriter fileWriter =
                    new FileWriter(fileName);

                BufferedWriter bufferedWriter =
                    new BufferedWriter(fileWriter);

                bufferedWriter.write(display);

                bufferedWriter.close();
            }
            catch(IOException ex) {
                System.out.println(
                    "Error writing to file '"
                    + fileName + "'");
            }
            topicArea.setText(display);
        }
     });


add(submitButton);
JLabel dtopicsTitle = new JLabel("                                                                           Topics:                                                                           ");
dtopicsTitle.setLocation(170, 3);
dtopicsTitle.setSize(150,30);
dtopicsTitle.setFont(new Font("Serif", Font.PLAIN, 25));
dtopicsTitle.setHorizontalAlignment(0);
add(dtopicsTitle);


topicrefreshButton = new JButton("Refresh Topics");
topicrefreshButton.setLocation(250, 30);
topicrefreshButton.setSize(100, 30);
topicrefreshButton.addActionListener(new ActionListener() {
    @Override
    public void actionPerformed(ActionEvent e) {

        topicArea.setText(display);

    }
});
add(topicrefreshButton);    


        topicArea = new JTextArea(40, 64);
        topicArea.setSize(650, 430);
        topicArea.setLineWrap(true);
        topicArea.setEditable(false);
        topicArea.setText(display);
        add(topicArea);
        JScrollPane topicScroll = new JScrollPane(topicArea);
        topicScroll.setSize(650,430);
        add(topicScroll);


}
}

感谢您提供的支持。

Applet
File
像油和水一样混合(即“不”)

不仅任何
文件
对象都不会指向您期望的位置(它们指向用户的本地文件系统,而不是服务器),而且小程序在使用文件之前需要经过数字签名和信任

小程序通常通过URL访问资源。如果URL可以相对于小程序的代码库、文档库或类路径形成,则它可以保持沙盒状态并仍然工作。否则,它将需要信任

其他提示
  • 确保配置为显示小程序和JWS应用程序。如果默认级别没有输出,请提高该级别并重试
  • 将形式为
    catch(异常e){..
    的代码更改为
    catch(异常e){e.printStackTrace();//非常有用!。
  • Java GUI可能必须在多个平台上工作,在不同的屏幕分辨率和使用不同的PLAF。因此,它们不利于组件的精确放置。要为一个健壮的GUI组织组件,请使用布局管理器,或者与布局填充和边框配合使用
  • 不要将Swing组件与AWT组件混用。(使用
    JApplet
    而不是
    Applet

  • 顺便说一句-现在浏览一下“代码之外的任何内容”,我注意到小程序确实是经过签名和信任的。但是无论如何都要使用
    URL
    。权限
    Codebase
    不应该在主部分而不是它们自己的单独部分吗?(即,将其上移到
    清单版本
    ,前面没有空行。)
    import java.awt.*;
    import java.awt.event.*;
    
    import javax.swing.*;
    
    import java.applet.*;
    import java.io.*;
    
    
    @SuppressWarnings("serial")
    public class Topics extends Applet {
    
    String name;
    String topics;
    String paragraphs;
    //reading file for existing posts
    String fileread = "Topics.txt";
    static String line = null;
    {
    try {
        FileReader fileReader = 
            new FileReader(fileread);
    
        BufferedReader bufferedReader = 
            new BufferedReader(fileReader);
    
        while((line = bufferedReader.readLine()) != null) {
            System.out.println(line);
        }   
    
        bufferedReader.close();         
    }
    catch(FileNotFoundException ex) {
        System.out.println(
            "Unable to open file '" + 
            fileread + "'");                
    }
    catch(IOException ex1) {
        System.out.println(
            "Error reading file '" 
            + fileread + "'");                  
    
    }
    }
    static String display = line;
    
    JPanel topicPanel;
    JLabel title, username, topic, paragraph, topicsTitle, dtopicsTitle;
    JTextField nameField, topicField;
    JButton submitButton, topicrefreshButton;
    JTextArea paragraphArea, topicArea;
    
    
    public void init() {
        final JPanel topicGUI = new JPanel();
        topicGUI.setLayout(null);
    
        setBackground(Color.GREEN);
    
        setVisible(true);
    
        // JLabels
    
        JLabel title = new JLabel("                                                                           Make A Post                                                                           ");
        title.setSize(150, 25);
        title.setFont(new Font("Serif", Font.PLAIN, 25));
        title.setHorizontalAlignment(0);
        add(title);
    
    
        JLabel username = new JLabel("Username: ");
        username.setSize(70, 15);
        username.setHorizontalAlignment(0);
        add(username);
    
        // JTextField
    
        nameField = new JTextField(8);
        nameField.setSize(150, 18);
        add(nameField);
    
        // JLabel
    
        JLabel topic = new JLabel("Topic: ");
        topic.setSize(40, 15);
        topic.setHorizontalAlignment(0);
        add(topic);
    
        // JTextField
    
        topicField = new JTextField(8);
        topicField.setSize(180, 18);
        add(topicField);
    
    
        //JLabel
    
        JLabel paragraph = new JLabel("                                                                                          Paragraph:                                                                                          ");
        paragraph.setSize(70, 15);
        paragraph.setHorizontalAlignment(0);
        add(paragraph);
    
        // JTextAreas
    
        paragraphArea = new JTextArea(8, 5);
        paragraphArea.setSize(700, 100);
        paragraphArea.setLineWrap(true);
        paragraphArea.setEditable(true);
        add(paragraphArea);
    
    
        // JButton
    
        JButton submitButton = new JButton("SUBMIT");
        submitButton.setSize(100, 30);
        submitButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
    
                name = nameField.getText();
                topics = topicField.getText();
                paragraphs = paragraphArea.getText();
    
    
    
                display ="\n" + "\t" + name + " - " + "\n" + "\t" + topics + " : " + "\n" + paragraphs + display + "\n";
    
                topicField.setText("");
                paragraphArea.setText("");
    
                //writing new info to file
                String fileName = "Topics.txt";
    
                try {
                    FileWriter fileWriter =
                        new FileWriter(fileName);
    
                    BufferedWriter bufferedWriter =
                        new BufferedWriter(fileWriter);
    
                    bufferedWriter.write(display);
    
                    bufferedWriter.close();
                }
                catch(IOException ex) {
                    System.out.println(
                        "Error writing to file '"
                        + fileName + "'");
                }
                topicArea.setText(display);
            }
         });
    
    
    add(submitButton);
    JLabel dtopicsTitle = new JLabel("                                                                           Topics:                                                                           ");
    dtopicsTitle.setLocation(170, 3);
    dtopicsTitle.setSize(150,30);
    dtopicsTitle.setFont(new Font("Serif", Font.PLAIN, 25));
    dtopicsTitle.setHorizontalAlignment(0);
    add(dtopicsTitle);
    
    
    topicrefreshButton = new JButton("Refresh Topics");
    topicrefreshButton.setLocation(250, 30);
    topicrefreshButton.setSize(100, 30);
    topicrefreshButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
    
            topicArea.setText(display);
    
        }
    });
    add(topicrefreshButton);    
    
    
            topicArea = new JTextArea(40, 64);
            topicArea.setSize(650, 430);
            topicArea.setLineWrap(true);
            topicArea.setEditable(false);
            topicArea.setText(display);
            add(topicArea);
            JScrollPane topicScroll = new JScrollPane(topicArea);
            topicScroll.setSize(650,430);
            add(topicScroll);
    
    
    }
    }