pack200 .gz file unpack and create .jar file in browser(speed test). - Java Applet Development

I have to test the speed after loading the .gz file in browser and I am having java applet based web application(Hello word) whose cache_Archive jar file size is 743byets and using pack200 tool compressed to .gz(321 bytes)files.
1) created HelloWorld.java file
    import java.applet.Applet;
    import java.awt.Graphics;
    public class HelloWorld extends Applet {
        public void paint(Graphics g) {
            g.drawString("Hello word!", 50, 25);
        }
    }Created HelloWorld123.jar file with this class
2)Main html file hello.html
<HTML>
    <head>
    <meta HTTP-EQUIV="Pragma" CONTENT="no-cache">
    <meta HTTP-EQUIV="Expires" CONTENT="-1">
  <meta HTTP-EQUIV="accept-encoding" CONTENT="gzip,deflate">
  <meta http-equiv="content-type" content="text/html">
  </head>
    <BODY>
    Here is the output of my program:
       <APPLET CODE    = "HelloWorld.class" ARCHIVE = "HelloWorld123.jar" WIDTH   = "200" HEIGHT  = "50">
        <param name="java_arguments" value="-Djnlp.packEnabled=true"/>
</APPLET>
    </BODY>
    </HTML>3)First time tried to load the class file from the jar file it works fine(HelloWorld.class is loading in the browser).
<APPLET CODE    = "HelloWorld.class" ARCHIVE = "HelloWorld123.jar" WIDTH   = "200" HEIGHT  = "50">4) created different .gz file with same jar file(pack200 tool).
HelloWorld123.gz
pack200 --gzip -E9 HelloWorld123.gz HelloWorld123.jar
HelloWorld123.jar.pack
pack200 --no-gzip -E9 HelloWorld123.jar.pack HelloWorld123.jar
HelloWorld123.jar.pack.gz
pack200 --gzip -E9 HelloWorld123.jar.pack.gz HelloWorld123.jar
and tried these files with the above html code
<APPLET CODE    = "HelloWorld.class" ARCHIVE = "HelloWorld123.gz"  WIDTH   = "200" HEIGHT  = "50" >or
<APPLET CODE    = "HelloWorld.class" ARCHIVE = "HelloWorld123.jar.pack"  WIDTH   = "200" HEIGHT  = "50" >or
<APPLET CODE    = "HelloWorld.class" ARCHIVE = "HHelloWorld123.jar.pack.gz"  WIDTH   = "200" HEIGHT  = "50" >while loading this class I found that class loader error on sun console(as follows).
    
liveconnect: Invoking JS method: document
liveconnect: Invoking JS method: URL
basic: Referencing classloader: sun.plugin.ClassLoaderInfo#23d275, refcount=1
basic: Added progress listener: sun.plugin.util.GrayBoxPainter$GrayBoxProgressListener#e85825
basic: Loading applet ...
basic: Initializing applet ...
basic: Starting applet ...
basic: completed perf rollup
network: Connecting http://localhost:7020/designer/details/HelloWorld123.pack.gz with proxy=DIRECT
network: Connecting socket://localhost:7020 with proxy=DIRECT
network: Connecting http://localhost:7020/designer/details/HelloWorld123.pack.gz with cookie "JSESSIONID=gGsmMJmbGmZhtyKTn1v2FWvcRkFhN18Dpm81R2RLM6LYvYfFLf25!-726539454"
network: Downloading resource: http://localhost:7020/designer/details/HelloWorld123.pack.gz
    Content-Length: 314
    Content-Encoding: null
load: class HelloWorld.class not found.
java.lang.ClassNotFoundException: HelloWorld.class
    at sun.applet.AppletClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.applet.AppletClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.applet.AppletClassLoader.loadCode(Unknown Source)
    at sun.applet.AppletPanel.createApplet(Unknown Source)
    at sun.plugin.AppletViewer.createApplet(Unknown Source)
    at sun.applet.AppletPanel.runLoader(Unknown Source)
    at sun.applet.AppletPanel.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
basic: Exception: java.lang.ClassNotFoundException: HelloWorld.class
Ignored exception: java.lang.ClassNotFoundException: HelloWorld.classIn the About detail I can get that HelloWorld123.pack.gz or HelloWorld123.jar.gz or HelloWorld123.jar.pack.gz is downloading.
My question is will browser decompress the .gz file to .jar file internally ? or I am missing some coding for .gz file decompression ?.

1. JAR files can be compressed.
2. ARCHIVE items have to be JAR files.

Related

Applet in JSP?

Hello,
Is it possible to include an applet in a JSP? If yes how's that done? I tried like I would do in a html page but it didn't work. 
Yes
refer
<jsp:plugin ..> </jsp:plugin> 
or by simple program
javaApplet.java
import java.applet.*;
import java.awt.*;
public class javaApplet extends Applet{
  public void paint(Graphics g){
    g.drawString("Welcome in Java Applet.",40,20);
  }
}test.jsp
<HTML>
<HEAD><title>Applet In Jsp</title>
</HEAD>
<BODY>
<APPLET ALIGN="CENTER" CODE="javaApplet.class" WIDTH="800" HEIGHT="500">
</APPLET>
</BODY>
</HTML> 
Just code it as you would normally, e.g.,
            <center><APPLET code="categoriesdialog.CategoriesDialog" archive="WhatWeHaveInCommon.jar" width=450 height=450>
                <param name=schema value="http://">
                <param name=category_server_name value="localhost">
                <param name=category_server_port value="8084">
                <param name=user_ID value="12345">
                <param name=category_server.password value="Foo">
            </APPLET></center>Now, passing parameters to the applet is another matter and one I posted a question on. For example, replacing "12345" with <%= my_local_variable %> should pass the contents of my_local_variable , but doesn't.
Bob 
Finally I am getting some replies. I have been stuck on this for 2 days now and I have tried everything without succes to the point that I started questioning if it's even doable. I hope you guys help me out to get this done.
I am using Tomcat on port 8080. My applet's class file is at the root of the project along with the JSP that calls it. I have tried both the applet tag and the plugin tag but the applet won't load and I keep getting this error in the browser's Java Console :
java.lang.ClassFormatError: Incompatible magic value 1014260066 in class file Applet1
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
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)
Exception : java.lang.ClassFormatError: Incompatible magic value 1014260066 in class file Applet1.
Here's the code in my JSP :
<jsp:plugin type="applet" code="Applet1.class"
        codebase="."
        width="400"
        height="300">
</jsp:plugin>Also, I kept the applet code as simple as possible to not to run into other problems:
import java.awt.Color;
import javax.swing.JApplet;
public class Applet1 extends JApplet{
     public void init(){
          
          getContentPane().setBackground(Color.green);
     }
}As for FractalBob, are the parameters you mentioned mandatory or just for the exemple? Maybe that's what I am missing? Because as I said, I had no problem launching the applet "locally" from an ordinary html page, and I am quite to new to using Tomcat and JEE. 
Hey guys I just found out a very weird thing. I removed the servlet that was calling the jsp and tried accessing the jsp directly, and then the applet loaded successfully. Why is that? What does it mean? 
It means that your servlet path is different from your jsp path.
When you forward from a Servlet to a JSP, that is a completely server side forward.
The requested URI does not change.
Thus any page relative links from the JSP do not necessarily work
eg Servlet: /myServlet
JSP: /jsp/myJsp.jsp
If the servlet forwards to that jsp,
accessing the servlet on url: http://localhost:8080/myApp/myServlet
accessing the jsp directly: http://localhost;8080/myApp/jsp/MyJsp.jsp
The path in the url is very different.
You were referencing the applet class in a relative way:
<jsp:plugin type="applet" code="Applet1.class"
        codebase="."
        width="400"
        height="300">
</jsp:plugin>You used a codebase of "." - current directory.
If you accessed it via the servlet, the web page would then go looking for the class at: http://localhost:8080/myApp/Applet1.class
Accessing it through the jsp: http://localhost;8080/myApp/jsp/MyJsp.jsp
You can see how the paths are different, and one would work where the other wouldn't.
Some potential solutions
1 - <base> tag in html. Specifies the path from which relative references on the page should be resolved.
2 - specify the path to the applet codebase as an absolute url from the webroot (including the context path: ie /myApp/appletClasses)
cheers,
evnafets 
Totally right. Thanks for explanations.

error message

hi there...
i converted a html page using html converter to run japplet in that page..
but when i ran that page in web browser , following error message echoed in the console..
   +*log4j:WARN No appenders could be found for logger (org.apache.struts.tiles.TilesServlet).*+
+*log4j:WARN Please initialize the log4j system properly.*+although i tried to understand it from diffrent resources but stilll not succeed.
below is the html page that has been converted..
         <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<link rel="stylesheet" href="theme/Master.css" type="text/css">
<title>mypage</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta name="GENERATOR" content="Rational Application Developer">
</head>
<body>
<!--"CONVERTED_APPLET"-->
<!-- HTML CONVERTER -->
<object
    classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
    codebase = "http://java.sun.com/update/1.5.0/jinstall-1_5-windows-i586.cab#Version=1,5,0,0"
    WIDTH = "300" HEIGHT = "200" ALT = "applet" >
    <PARAM NAME = CODE VALUE = "mypack.Personal_info.class" >
<PARAM NAME = CODEBASE VALUE = "RegistrationApplet" >
    <param name = "type" value = "application/x-java-applet;version=1.5">
    <param name = "scriptable" value = "false">
    <comment>
     <embed
            type="application/x-java-applet;version=1.5"  \ CODE = "mypack.Personal_info.class" \ JAVA_CODEBASE = "RegistrationApplet" \ ALT = "applet" \ WIDTH = "300" \ HEIGHT = "200" 
            pluginspage="http://java.sun.com/products/plugin/index.html#download">
         <noembed>
           
            </noembed>
     </embed>
    </comment>
</object>
<!--
<APPLET CODE = "Personal_info.class" JAVA_CODEBASE = "RegistrationApplet" ARCHIVE = "SwingApplet.jar" WIDTH = "300" HEIGHT = "200" ALT = "applet">
</APPLET>
-->
<!--"END_CONVERTED_APPLET"-->
</body>
</html>and this is japplet class that is to be embed in html page above.
          package mypack;
import java.awt.*;
import javax.swing.*;
public class Personal_info extends JApplet {
     private JPanel jContentPane = null;
     private JTextField jTextField = null;
     /**
      * This is the xxx default constructor
      */
     public Personal_info() {
          super();
     }
     /**
      * This method initializes this
      *
      * #return void
      */
     public void init() {
          this.setSize(300, 200);
          this.setContentPane(getJContentPane());
     }
     /**
      * This method initializes jContentPane
      *
      * #return javax.swing.JPanel
      */
     private JPanel getJContentPane() {
          if (jContentPane == null) {
               jContentPane = new JPanel();
               jContentPane.setLayout(null);
               jContentPane.add(getJTextField(), null);
          }
          return jContentPane;
     }
     /**
      * This method initializes jTextField     
      *      
      * #return javax.swing.JTextField     
      */
     private JTextField getJTextField() {
          if (jTextField == null) {
               jTextField = new JTextField();
               jTextField.setBounds(new Rectangle(70, 72, 137, 20));
          }
          return jTextField;
     }
}so if someone already know this error, then please let me know too.
thanks.. 
First it is a warning and not an error so you could ignore it if you wish.
Second it is on the server and not in the applet. Note the reference to the class org.apache.struts.tiles.TilesServlet in the message.
Third this may help explain more: http://www.myeclipseide.com/PNphpBB2+file-viewtopic-t-14074.html 
thanks Mr tolmak for ur quick reply..
now if u please dont mind then please fix my actual problem that made me very much annoyed since a week..
i want to run an japplet in a html page and as usual for that i used htmlconverter 1.6 ( from jdk1.6.0_02) to convert the html page in specific form..now when i tried to run this html form in firefox IE7 NS 9.0, i got same error message
applet myapplet not inited with a red cross at the place where applet would displayed.
in my web browsers tool->option->sun java i have checked the use jre *1.6.0_03 for applet (requered restart)* option.
rest of settings required for embedding japplet in web page has been done also(how much i know) but the problem still not solved.
so please tell me where i m doing wrong ..
thanks 
Have you checked the FireFox error console for error messgaes? It is under the tools menu option 
neither firefox nor netscape displayed any error in their java console
but in IE the following exception echoed
java.lang.NoClassDefFoundError: Personal_info (wrong name: mypack/Personal_info)
     at java.lang.ClassLoader.defineClass1(Native Method)
     at java.lang.ClassLoader.defineClass(Unknown Source)
     at java.security.SecureClassLoader.defineClass(Unknown Source)
     at sun.applet.AppletClassLoader.findClass(Unknown Source)
     at java.lang.ClassLoader.loadClass(Unknown Source)
     at sun.applet.AppletClassLoader.loadClass(Unknown Source)
     at java.lang.ClassLoader.loadClass(Unknown Source)
     at sun.applet.AppletClassLoader.loadCode(Unknown Source)
     at sun.applet.AppletPanel.createApplet(Unknown Source)
     at sun.plugin.AppletViewer.createApplet(Unknown Source)
     at sun.applet.AppletPanel.runLoader(Unknown Source)
     at sun.applet.AppletPanel.run(Unknown Source)
     at java.lang.Thread.run(Unknown Source)
one more quary....
in my computer three web browser are installed and when i used htmlconverter to convert html page given above then system's default web browser was Netscape navigator. now is it possible to distplay the japplet class in diffrent web browser(ie in IE,firefox) as i know the code generated by htmlconverter is according to the web browser used.
thanks..

static variables and JAR files problem

Hello All,
I am trying to get two applets to communicate.
Both are held in the same JAR file loaded from the same location. The JAR file also contains a class with some static variables which are used to comunicate between the two applets.
The applets are on separate frames in the browser and the system works fine when I don't use a JAR file but when I put the class files into a JAR file, each applet has it's own static variables (not very static).
Can anyone tell me why static variables stop working when the code is loaded from a JAR file.
Thanks in advance,
Alastair. 
I know that since version 1.3.1 the java plug-in uses separate classloaders for applets that have different codebases and/or different archive parameters. Only if they have the same codebase and have the same value in the archive parameter will the same classloader be used. (the scope of a static variable is classloader) 
Hi YoGee,
I only have one JAR file which contains three classes.
appSend.class -> which gets some user input and sets static variables
in details.class
details.class -> which contains the static variables.
appReceive.class -> displays the contents of the static variables.
The two HTML files are in separate folders but the JAR file is the same for both.
Classes\ -> contains the JAR file (myCode.JAR)
Sender\ -> contains the HTML file appSender.html (see below for
Applet tag)
Receiver\ -> contains the HTML file appReceiver.html (see below for
Applet tag)
appSender.html
--------------
<HTML>
<HEAD>
</HEAD>
<BODY BGCOLOR="000000">
<CENTER>
<APPLET
     name = "appSender"
     code     = "appSend.class"
     archive = "../Classes/myCode.JAR"
     width     = "500"
     height     = "300"
     >
</APPLET>
</CENTER>
</BODY>
</HTML>
appReceiver.html
----------------
<HTML>
<HEAD>
</HEAD>
<BODY BGCOLOR="000000">
<CENTER>
<APPLET
     name = "appReceiver"
     code     = "appReceive.class"
     archive = "../Classes/myCode.JAR"
     width     = "500"
     height     = "300"
     >
</APPLET>
</CENTER>
</BODY>
</HTML>
When I don't use the JAR file i.e. the Classes\ folder contains the three class files and the html files use
codebase = "..\Classes"
insead of the archive tag, everything works. But when I use JAR files (which are loaded from the same folder) the two applets seem to load separate versions of details.class
Is this because of what you have said? (Sorry if that's a daft question)
If so, do you know what I am doing wrong? or is there a way to load details.class from somewhere else (a common location) outside the JAR file?
can you set an archive tag AND a codebase tag?
Regards,
Alastair. 
can you set an archive tag AND a codebase tag?Yes, did you try that? 
Not yet, but I will now.
Thanks!!! 
Ok,
I've just tried the below setup and I get the following security exception:
java.security.AccessControlException: access denied (java.util.PropertyPermission java.home read)
at java.security.AccessControlContext.checkPermission(Unknown Source)
at java.security.AccessController.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPropertyAccess(Unknown Source)
at java.lang.System.getProperty(Unknown Source)
at sun.plugin.security.PluginClassLoader.getPermissions(Unknown Source)
at java.security.SecureClassLoader.getProtectionDomain(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at sun.applet.AppletClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.applet.AppletClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at appSend.init(appSend.java:62)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
I now have one JAR file which contains the two classes.
appSend.class & appReceive.class
and a separate details.class file
The two HTML files are in separate folders but the JAR file is still the same for both.
Classes\ -> contains the JAR file (myCode.JAR) and details.class
Sender\ -> contains the HTML file appSender.html (see below for
Applet tag)
Receiver\ -> contains the HTML file appReceiver.html (see below for
Applet tag)
appSender.html
--------------
<HTML>
<HEAD>
</HEAD>
<BODY BGCOLOR="000000">
<CENTER>
<APPLET
name = "appSender"
code = "appSend.class"
archive = "myCode.JAR"
codebase = "../Classes"
width = "500"
height = "300"
>
</APPLET>
</CENTER>
</BODY>
</HTML>
appReceiver.html
----------------
<HTML>
<HEAD>
</HEAD>
<BODY BGCOLOR="000000">
<CENTER>
<APPLET
name = "appReceiver"
code = "appReceive.class"
archive = "myCode.JAR"
codebase = "../Classes"
width = "500"
height = "300"
>
</APPLET>
</CENTER>
</BODY>
</HTML>
Is this how it should be? or have I made a mistake with the tags?
Can the ClassLoaders in either applet see the details.class file through the codebase tag?
I'm guessing from the security exception that the ClassLoader for each applet can only load classes from within the JAR file? and can't just use the codebase tag, which is not very helpful!
Thanks for your help so far.
Regards,
Alastair.
Please ignore the previous posting.
I was very stupidly trying to test the code by running it locally on my machine where the applet would not have permission to load the files from anyway.
I have put the files onto a test website and it works fine.
Thank you very much for your help YoGee, It's very much appreciated.
Regards,
Alastair. 
Ok, I did a small test:
In the /classes dir:
Details.class:
public class Details {
  public static String staticString;
}AppSender.class [in myCode.jar]
public class AppSender extends java.applet.Applet {
  public void init() {
    System.out.println(Details.staticString);
    Details.staticString = "test";
    System.out.println(Details.staticString);
  }
}AppReceiver.class [in myCode.jar]
public class AppReceiver extends java.applet.Applet {
  public void init() {
    System.out.println(Details.staticString);
  }
}In the /sender dir:
AppSender.html
<html>
  <head>
      <title>AppSender</title>
  </head>
  <body>
      <h1>AppSender</h1>
      <hr>
      <applet codebase = "../classes" archive = "myCode.jar" code="AppSender.class" width=300 height=100>
      </applet>
      <hr>
  </body>
</html>In the /receiver dir:
AppReceiver.html
<html>
  <head>
      <title>AppReceiver</title>
  </head>
  <body>
      <h1>AppReceiver</h1>
      <hr>
      <applet codebase = "../classes" archive = "myCode.jar" code="AppReceiver.class" width=300 height=100>
      </applet>
      <hr>
  </body>
</html>If I launch AppSender.html and then AppReceiver.html, in the java console I can see:
null
test
test
This means that they must be using the same classloader since the AppReciever class was accessing the same static variable as the AppSender class. 
I have put the files onto a test website and it works
fine.Ah, in that case ignore my last post!
Thank you very much for your help YoGee, It's very
much appreciated.No problem.

Class not found in signed applet

Hello
I am using a signed applet and am getting a class not found exception
this works fine when i run it in the IDE but get the exception when i try to load the applet from the web browser in the application.
java.lang.ClassNotFoundException: MyApplet
at sun.applet.AppletClassLoader.findClass(AppletClassLoader.java:162)
at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
at sun.applet.AppletClassLoader.loadClass(AppletClassLoader.java:123)
at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
at sun.applet.AppletClassLoader.loadCode(AppletClassLoader.java:566)
at sun.applet.AppletPanel.createApplet(AppletPanel.java:619)
at sun.plugin.AppletViewer.createApplet(Unknown Source)
at sun.applet.AppletPanel.runLoader(AppletPanel.java:548)
at sun.applet.AppletPanel.run(AppletPanel.java:299)
at java.lang.Thread.run(Thread.java:534)
Caused by: java.io.IOException: open HTTP connection failed.
at sun.applet.AppletClassLoader.getBytes(AppletClassLoader.java:265)
at sun.applet.AppletClassLoader.access$100(AppletClassLoader.java:43)
at sun.applet.AppletClassLoader$1.run(AppletClassLoader.java:152)
at java.security.AccessController.doPrivileged(Native Method)
at sun.applet.AppletClassLoader.findClass(AppletClassLoader.java:149)
... 9 more
I have my applet code in the applet folder
here is my jsp call
<applet code="MyApplet" codebase="../applet" archive="SMyApplet.jar" width=400 height=400>
</applet>
here is my applet code
package applet;
import java.applet.*;
import java.awt.*;
public class MyApplet extends Applet
{
public void paint(Graphics g)
{
g.drawString("Generate Me",50, 50);
}
} 
Review this tutorial and you should find the problem:
http://java.sun.com/docs/books/tutorial/deployment/applet/html.html 
Thanks for the info that helped.
I figued out the problem the follwing did the trick
<applet code="applet.MyApplet.class" codebase="." archive="SMyApplet.jar" width=400 height=400>
</applet> 
If i do
<APPLET CODE="xxx.class" CODEBASE="." ARCHIVE = "skshrad.jar , javax.jar" WIDTH=500 HEIGHT=500>
is it correct?
because it still appeared class not found error..
This is a signed applet
thanks..
i try to put 2 directories in a jar also did not work..

Japplet file problems

I am trying to create an applet that will access the client's file system within our intranet to allow the to chose a file to upload. The problem I am having is that I am unable to read the client FS in an object tag however when I use the applet tag it works every time.
Ii am using a signed applet and I am trusting it however the applet within the object tag does not load. I have attached everything that I think would be be pertinent. Any help would be greatly appreciated.
Thanks
I am using the following Java environment:
java version "1.6.0_01"
Java(TM) SE Runtime Environment (build 1.6.0_01-b06)
Java HotSpot(TM) Client VM (build 1.6.0_01-b06, mixed mode, sharing)
Here is my Java Code:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
// To get the netscape javascript library you must compile like this
//javac -classpath c:\progra~1\java\jdk1.6.0_01\jre\lib\plugin.jar WebScanRemoteControl.java
import netscape.javascript.*;
public class TestApplet extends JApplet implements ActionListener,MouseListener{
     
     private static final long serialVersionUID = 1L;
     //My GUI objects
     private JButton OpenBTN;
     private JTextArea FileLisTxt;
     private JFileChooser fc;
     
     public void init() {
                                             
          final Container pane = getContentPane();
          setSize(200, 200);          
          
          FileLisTxt = new JTextArea();
          OpenBTN = new JButton("Run");
          OpenBTN.addActionListener(this);
          fc = new JFileChooser();
                    
          //Set the pane layout type
          pane.setLayout(null);
          
          //Set the location of the elements (x,y)
          FileLisTxt.setLocation(5,5);
          OpenBTN.setLocation(5, 60);
          fc.setLocation(5, 85);
          
          //Set the size of the elements (Width,Height)
          FileLisTxt.setSize(75,50);
          OpenBTN.setSize(75, 20);
          fc.setSize(180, 100);
          
          //Add elements to the pane
          pane.add(FileLisTxt);
          pane.add(OpenBTN);
          pane.add(fc);
     }
     
     public void actionPerformed(final ActionEvent e) {
                    
          if (e.getSource() == OpenBTN) {
                    JSObject win = JSObject.getWindow(this);
                    JSObject doc = (JSObject) win.getMember("document");
                    JSObject loc = (JSObject) doc.getMember("location");
                    
                    String s = (String) loc.getMember("href"); // document.location.href
                    win.call("f", null); // Call f() in HTML page               
                    FileLisTxt.append(s);                                        
          }          
     }
     
     public void mouseClicked(final MouseEvent e) {
JOptionPane.showMessageDialog(null,"FileName","WARNING",JOptionPane.INFORMATION_MESSAGE);
     }
     
     public void mousePressed(final MouseEvent e){}
     public void mouseReleased(final MouseEvent e){}
     public void mouseEntered(final MouseEvent e){}
     public void mouseExited(final MouseEvent e)     {}
}
MY HTML page is this:
<html>
<head>
<title>Untitled Document</title>
<script language="Javascript">
function f() {
     alert("this function has been called");
}
</script>
</head>
<body>
<OBJECT id="basicApplet" classid="clsid:CAFEEFAC-0016-0000-0000-ABCDEFFEDCBA" archive="TestApplet.jar" width="250" height="600" codebase="http://java.sun.com/update/1.6.0/jinstall-6-windows-i586.cab#Version=6,0,0,99">
<PARAM name="code" value="TestApplet.class">
<PARAM NAME="MAYSCRIPT" VALUE="true">
<PARAM NAME="UserDirectory" VALUE="C:\\scanned">     
</OBJECT>
<APPLET CODE="TestApplet.class" archive="TestApplet.jar" WIDTH=250 HEIGHT=600>
     <PARAM NAME="MAYSCRIPT" VALUE="true">
</APPLET>
</body>
</html> 
This is the policy file.
/* AUTOMATICALLY GENERATED ON Tue Apr 16 17:20:59 EDT 2002*/
/* DO NOT EDIT */
grant {
  permission java.security.AllPermission;
};This is the error.
java.security.AccessControlException: access denied (java.util.PropertyPermission user.dir read)
     at java.security.AccessControlContext.checkPermission(Unknown Source)
     at java.security.AccessController.checkPermission(Unknown Source)
     at java.lang.SecurityManager.checkPermission(Unknown Source)
     at java.lang.SecurityManager.checkPropertyAccess(Unknown Source)
     at java.lang.System.getProperty(Unknown Source)
     at java.io.Win32FileSystem.getUserPath(Unknown Source)
     at java.io.Win32FileSystem.resolve(Unknown Source)
     at java.io.File.getAbsolutePath(Unknown Source)
     at sun.awt.shell.Win32ShellFolder2.<init>(Unknown Source)
     at sun.awt.shell.Win32ShellFolder2.listFiles(Unknown Source)
     at sun.awt.shell.ShellFolder.listFiles(Unknown Source)
     at sun.awt.shell.Win32ShellFolderManager2.get(Unknown Source)
     at sun.awt.shell.ShellFolder.get(Unknown Source)
     at javax.swing.plaf.metal.MetalFileChooserUI.updateUseShellFolder(Unknown Source)
     at javax.swing.plaf.metal.MetalFileChooserUI.installComponents(Unknown Source)
     at javax.swing.plaf.basic.BasicFileChooserUI.installUI(Unknown Source)
     at javax.swing.plaf.metal.MetalFileChooserUI.installUI(Unknown Source)
     at javax.swing.JComponent.setUI(Unknown Source)
     at javax.swing.JFileChooser.updateUI(Unknown Source)
     at javax.swing.JFileChooser.setup(Unknown Source)
     at javax.swing.JFileChooser.<init>(Unknown Source)
     at javax.swing.JFileChooser.<init>(Unknown Source)
     at TestApplet.init(TestApplet.java:24)
     at sun.applet.AppletPanel.run(Unknown Source)
     at java.lang.Thread.run(Unknown Source) 
This is the policy file.Don't worry about that it is ancillary.
/* AUTOMATICALLY GENERATED ON Tue Apr 16 17:20:59 EDT
2002*/
/* DO NOT EDIT */
grant {
permission java.security.AllPermission;This is the error.
java.security.AccessControlException: access denied
(java.util.PropertyPermission user.dir read)You are throwing a security exception and this means your security implementation is not properly qualified.
I assume you are using the proper java plugin BTW.
To test this easier first remove the java script and reduce the page to its simplest case sans HTMLConverter code
ie:
<HTML>
<HEAD><TITLE>Test Applet</TITLE></HEAD>
<BODY>
<APPLET code="TestApplet.class"
archive="TestApplet.jar" WIDTH=250 HEIGHT=600>
</APPLET>
</BODY>
</HTML>Now save this script as "compileTest.bat"
//------ Compile and pack script
javac -g -classpath .;%CLASSPATH% TestApplet.java
del TestApplet.jar
jar cf tmp.jar *.class *.gif *.jpg *.au
jarsigner -keystore[b] [YOUR_KEYSTORE_NAME_AND_DIR] -signedjar TestApplet.jar tmp.jar[b] [YOUR_CERTIFICATE_NAME_IN_KEYSTORE]
del tmp.jar
del *.class
//------ /Compile and pack script
This is the proper way to do this and gives your Applet complete unfettered machine control.
If you try my HyperView Applet (Working on TextPane.class ATM but waylaid FTM on java.home incorrect parameter issue)
https://hyperview.dev.java.net/
You will see it writes a file called Hyperview.dat and saves various parameters into the windows registry.
(Work in progress)
Of course this is with the assumption that you have a proper certificate appropriately stored in your keystore.
Good Luck!
(T) 
Thanks that works perfectly. I was having to go in circles. Somehow I was able to get initial access and the next time the applet loaded it failed.
Thanks for the help. 
hello I've got the same problem , my applet couldn't read files from client computer...
I tried the keytool to create keystore or what , but vista commandprompt didn't understand my "keytool" command, what should i do???
Isn't there a simplier way to sign java applets. I searched control panel , and there the Java option, there is security tab,and inside it you can import some
certificates ... what are these???you must import som .p12 or .csr files .Is it possible to make my applet be trusted for the client with them??
Sorry for my english :) 
Where can I find {color:#ff0000}WebScanRemoteControl.java{color}? I don't have this file on the my computer. Please to help me. Thank you.

Categories

Resources