Avatar of akah123
akah123
Flag for United Kingdom of Great Britain and Northern Ireland

asked on 

Can not load applet class into browser

HI there,

I am tring to create a web browser that run's as an applet. I am using tomcat 6 and have placed my html file and my jar file in the relevant root directory (C://Program files/Apache Software foundation/Tomcat 6.0/webapps/ROOT). I have signed my jar file as I will need to gain access to the clients hardrive. This went through successfully. My jar file is called Mini_Browser_app.jar and the html is called Mini_Browser_app.html. The applet works fine when it is run via the appletviewer. I have tried to load the jar file by the relevant html. However I keep on getting this error message:

load: class Mini_Browser_app.class not found.
java.lang.ClassNotFoundException: Mini_Browser_app.class
      at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
      at java.lang.ClassLoader.loadClass(Unknown Source)
      at java.lang.ClassLoader.loadClass(Unknown Source)
      at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Unknown Source)
      at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source)
      at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
      at java.lang.Thread.run(Unknown Source)
Caused by: java.io.IOException: open HTTP connection failed:http://localhost:8080/Mini_Browser_app.jar/Mini_Browser_app/class.class
      at sun.plugin2.applet.Applet2ClassLoader.getBytes(Unknown Source)
      at sun.plugin2.applet.Applet2ClassLoader.access$000(Unknown Source)
      at sun.plugin2.applet.Applet2ClassLoader$1.run(Unknown Source)
      at java.security.AccessController.doPrivileged(Native Method)
      ... 7 more
Exception: java.lang.ClassNotFoundException: Mini_Browser_app.class
load: class Mini_Browser_app.class not found.
java.lang.ClassNotFoundException: Mini_Browser_app.class
      at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
      at java.lang.ClassLoader.loadClass(Unknown Source)
      at java.lang.ClassLoader.loadClass(Unknown Source)
      at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Unknown Source)
      at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source)
      at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
      at java.lang.Thread.run(Unknown Source)
Caused by: java.io.IOException: open HTTP connection failed:http://localhost:8080/Mini_Browser_app.jar/Mini_Browser_app/class.class
      at sun.plugin2.applet.Applet2ClassLoader.getBytes(Unknown Source)
      at sun.plugin2.applet.Applet2ClassLoader.access$000(Unknown Source)
      at sun.plugin2.applet.Applet2ClassLoader$1.run(Unknown Source)
      at java.security.AccessController.doPrivileged(Native Method)
      ... 7 more
Exception: java.lang.ClassNotFoundException: Mini_Browser_app.class
load: class Mini_Browser_app not found.
java.lang.ClassNotFoundException: Mini_Browser_app
      at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
      at java.lang.ClassLoader.loadClass(Unknown Source)
      at java.lang.ClassLoader.loadClass(Unknown Source)
      at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Unknown Source)
      at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source)
      at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
      at java.lang.Thread.run(Unknown Source)
Caused by: java.io.IOException: open HTTP connection failed:http://localhost:8080/Mini_Browser_app.jar/Mini_Browser_app.class
      at sun.plugin2.applet.Applet2ClassLoader.getBytes(Unknown Source)
      at sun.plugin2.applet.Applet2ClassLoader.access$000(Unknown Source)
      at sun.plugin2.applet.Applet2ClassLoader$1.run(Unknown Source)
      at java.security.AccessController.doPrivileged(Native Method)
      ... 7 more
Exception: java.lang.ClassNotFoundException: Mini_Browser_app

//html code
 
<HTML>
<Head>
<Title> A Simple Program </Title>
<Body>
 
<Applet codebase = "Mini_Browser_app.jar"
Code="Mini_Browser_app" 
ARCHIVE = "Mini_Browser_app.jar"
width="150" height="50">
</Applet>
 
</Body>
</HTML> 
 
//applet code
 
import java.applet.*;
import java.net.*;
 
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.util.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.text.html.*;
 
public class Mini_Applet_Browser extends Applet implements HyperlinkListener {
	    // These are the buttons for iterating through the page list.
	    private JButton backButton, forwardButton;
	    
	    // Page location text field.
	    private JTextField locationTextField;
	    
	    // Editor pane for displaying pages.
	    private JEditorPane displayEditorPane;
	    
	    // Browser's list of pages that have been visited.
	    private ArrayList pageList = new ArrayList();
	    
	    // Constructor for Mini Web Browser.
	    public void init() {
	        // Set application title.
	        //super("Mini Browser");
	        
	        // Set window size.
	        setSize(640, 480);
	        
	        /** Handle closing events.
	        addWindowListener(new WindowAdapter() {
	            public void windowClosing(WindowEvent e) {
	                actionExit();
	            }
	        }  };
	        **/
	  
	        
	        
	        // Set up file menu.
	        JMenuBar menuBar = new JMenuBar();
	        JMenu fileMenu = new JMenu("File");
	        fileMenu.setMnemonic(KeyEvent.VK_F);
	        JMenuItem fileExitMenuItem = new JMenuItem("Exit",
	                KeyEvent.VK_X);
	        fileExitMenuItem.addActionListener(new ActionListener() {
	            public void actionPerformed(ActionEvent e) {
	                actionExit();
	            }
	        });
	        fileMenu.add(fileExitMenuItem);
	        menuBar.add(fileMenu);
	        //setJMenuBar(menuBar);
	        this.add(menuBar);
	        
	        // Set up button panel.
	        JPanel buttonPanel = new JPanel();
	        backButton = new JButton("< Back");
	        backButton.addActionListener(new ActionListener() {
	            public void actionPerformed(ActionEvent e) {
	                actionBack();
	            }
	        });
	        backButton.setEnabled(false);
	        buttonPanel.add(backButton);
	        forwardButton = new JButton("Forward >");
	        forwardButton.addActionListener(new ActionListener() {
	            public void actionPerformed(ActionEvent e) {
	                actionForward();
	            }
	        });
	        forwardButton.setEnabled(false);
	        buttonPanel.add(forwardButton);
	        locationTextField = new JTextField(35);
	        locationTextField.addKeyListener(new KeyAdapter() {
	            public void keyReleased(KeyEvent e) {
	                if (e.getKeyCode() == KeyEvent.VK_ENTER) {
	                    actionGo();
	                }
	            }
	        });
	        buttonPanel.add(locationTextField);
	        JButton goButton = new JButton("GO");
	        goButton.addActionListener(new ActionListener() {
	            public void actionPerformed(ActionEvent e) {
	                actionGo();
	            }
	        });
	        buttonPanel.add(goButton);
	        
	        // Set up page display.
	        displayEditorPane = new JEditorPane();
	        displayEditorPane.setContentType("text/html");
	        displayEditorPane.setEditable(false);
	        displayEditorPane.addHyperlinkListener(this);
	        /**
	        getContentPane().setLayout(new BorderLayout());
	        getContentPane().add(buttonPanel, BorderLayout.NORTH);
	        getContentPane().add(new JScrollPane(displayEditorPane),
	                BorderLayout.CENTER);
	    }
	    **/
	        this.setLayout(new BorderLayout());
	        this.add(buttonPanel, BorderLayout.NORTH);
	        this.add(new JScrollPane(displayEditorPane),
	                BorderLayout.CENTER);
	    }
	        
	    // Exit this program.
	    private void actionExit() {
	        System.exit(0);
	    }
	    
	    // Go back to the page viewed before the current page.
	    private void actionBack() {
	        URL currentUrl = displayEditorPane.getPage();
	        int pageIndex = pageList.indexOf(currentUrl.toString());
	        try {
	            showPage(
	                    new URL((String) pageList.get(pageIndex - 1)), false);
	        } catch (Exception e) {}
	    }
	    
	    // Go forward to the page viewed after the current page.
	    private void actionForward() {
	        URL currentUrl = displayEditorPane.getPage();
	        int pageIndex = pageList.indexOf(currentUrl.toString());
	        try {
	            showPage(
	                    new URL((String) pageList.get(pageIndex + 1)), false);
	        } catch (Exception e) {}
	    }
	    
	    // Load and show the page specified in the location text field.
	    private void actionGo() {
	        URL verifiedUrl = verifyUrl(locationTextField.getText());
	        if (verifiedUrl != null) {
	            showPage(verifiedUrl, true);
	        } else {
	            showError("Invalid URL");
	        }
	    }
	    
	    // Show dialog box with error message.
	    private void showError(String errorMessage) {
	        JOptionPane.showMessageDialog(this, errorMessage,
	                "Error", JOptionPane.ERROR_MESSAGE);
	    }
	    
	    // Verify URL format.
	    private URL verifyUrl(String url) {
	        // Only allow HTTP URLs.
	        if (!url.toLowerCase().startsWith("http://"))
	            return null;
	        
	        // Verify format of URL.
	        URL verifiedUrl = null;
	        try {
	            verifiedUrl = new URL(url);
	        } catch (Exception e) {
	            return null;
	        }
	        
	        return verifiedUrl;
	    }
	    
	  /* Show the specified page and add it to
	     the page list if specified. */
	    private void showPage(URL pageUrl, boolean addToList) {
	        // Show hour glass cursor while crawling is under way.
	        setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
	        
	        try {
	            // Get URL of page currently being displayed.
	            URL currentUrl = displayEditorPane.getPage();
	            
	            // Load and display specified page.
	            displayEditorPane.setPage(pageUrl);
	            
	            // Get URL of new page being displayed.
	            URL newUrl = displayEditorPane.getPage();
	            
	            // Add page to list if specified.
	            if (addToList) {
	                int listSize = pageList.size();
	                if (listSize > 0) {
	                    int pageIndex =
	                            pageList.indexOf(currentUrl.toString());
	                    if (pageIndex < listSize - 1) {
	                        for (int i = listSize - 1; i > pageIndex; i--) {
	                            pageList.remove(i);
	                        }
	                    }
	                }
	                pageList.add(newUrl.toString());
	            }
	            
	            // Update location text field with URL of current page.
	            locationTextField.setText(newUrl.toString());
	            
	            // Update buttons based on the page being displayed.
	            updateButtons();
	        } catch (Exception e) {
	            // Show error messsage.
	            showError("Unable to load page");
	        } finally {
	            // Return to default cursor.
	            setCursor(Cursor.getDefaultCursor());
	        }
	    }
	    
	  /* Update back and forward buttons based on
	     the page being displayed. */
	    private void updateButtons() {
	        if (pageList.size() < 2) {
	            backButton.setEnabled(false);
	            forwardButton.setEnabled(false);
	        } else {
	            URL currentUrl = displayEditorPane.getPage();
	            int pageIndex = pageList.indexOf(currentUrl.toString());
	            backButton.setEnabled(pageIndex > 0);
	            forwardButton.setEnabled(
	                    pageIndex < (pageList.size() - 1));
	        }
	    }
	    
	    // Handle hyperlink's being clicked.
	    public void hyperlinkUpdate(HyperlinkEvent event) {
	        HyperlinkEvent.EventType eventType = event.getEventType();
	        if (eventType == HyperlinkEvent.EventType.ACTIVATED) {
	            if (event instanceof HTMLFrameHyperlinkEvent) {
	                HTMLFrameHyperlinkEvent linkEvent =
	                        (HTMLFrameHyperlinkEvent) event;
	                HTMLDocument document =
	                        (HTMLDocument) displayEditorPane.getDocument();
	                document.processHTMLFrameHyperlinkEvent(linkEvent);
	            } else {
	                showPage(event.getURL(), true);
	            }
	        }
	    }
	    
	   
 
}

Open in new window

Editors IDEsWeb ServersServer Hardware

Avatar of undefined
Last Comment
Mick Barry

8/22/2022 - Mon