首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Web论坛小程序可在小程序查看器中工作,但不能在浏览器中工作

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

Stack Overflow用户
提问于 2014-01-02 11:48:33
回答 1查看 407关注 0票数 0

我在一个已经开发了一段时间的嵌入式applet上遇到了问题。小程序的jar被签名并被授予所有权限,并且它在小程序查看器中运行得很好。在浏览器中加载时,只会出现一个带有错误徽标的空白框,而我的小程序应该在该位置。单击时,它将返回"java.lang.invocationtargetexception“。我正在使用一种基本的HTML格式来嵌入applet。下面是我用来显示它的HTML代码:

代码语言:javascript
复制
<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> 

下面是Java控制台转储线程列表:

代码语言:javascript
复制
Dump thread list ...
Group main,ac=19,agc=2,pri=10
    main,5,alive
    traceMsgQueueThread,5,alive,daemon
    Timer-0,5,alive
    AWT-Shutdown,5,alive
    AWT-Windows,6,alive,daemon
    Java Plug-In Pipe Worker Thread (Client-Side),5,alive,daemon
    AWT-EventQueue-0,6,alive
    SysExecutionTheadCreator,5,alive,daemon
    MemoryCache-DelayedCleanup,5,alive,daemon
    CacheMemoryCleanUpThread,5,alive,daemon
    Browser Side Object Cleanup Thread,5,alive
    JVM[id=1]-Heartbeat,5,alive,daemon
Group Plugin Thread Group,ac=4,agc=0,pri=10
    AWT-EventQueue-1,6,alive
    Image Fetcher 0,8,alive,daemon
    TimerQueue,5,alive,daemon
    SysExecutionThead,5,alive,daemon
Group http://25.2.202.42/-threadGroup,ac=4,agc=0,pri=4
    Applet 1 LiveConnect Worker Thread,4,alive
    AWT-EventQueue-2,4,alive
    TimerQueue,4,alive,daemon
    ConsoleTraceListener,4,alive,daemon
Done.

以下是已签名jar的清单:

代码语言:javascript
复制
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/

我看不出错误是由我的代码本身导致的,但这里只是以防万一:

代码语言:javascript
复制
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);


}
}

感谢您能提供的任何支持。

EN

回答 1

Stack Overflow用户

发布于 2014-01-02 14:17:39

AppletFile就像油和水一样混合(即“非”)。

File对象不仅不会指向您期望的位置(它们指向用户的本地文件系统,而不是服务器),而且需要对小程序进行数字签名和信任,然后才能使用文件。

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

其他技巧

  1. 确保Java Console配置为显示小应用程序和JWS应用程序。如果在默认级别没有输出,请提高并重试。
  2. catch (Exception e) { ..表单代码更改为GUI可能需要在许多平台上工作,在不同的屏幕分辨率上&使用不同的平台。因此,它们不利于零部件的精确放置。要组织组件以获得健壮的图形用户界面,请使用布局管理器,或者combinations of them,以及布局填充和边框,用于white space.
  3. Don't混合使用Swing组件和AWT组件。(使用Applet.)

而不是JApplet

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20876046

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档