开发者

About JSP and SIgned applets

Here's the JSP page applet tags:

<applet code="localfile" width=150 height=150>
  <param name="archive" value="localfile.jar">
</applet>

Applet Code is:

package locf;

import java.applet.*;
import java.util.*;
import java.lang.*;
import java.io.*;


public class localfile extends Applet
{

    @Override
    public void init() {}

    @Override
public void start(){

        String s,uno,des = null;
        try {

            Process p = Runtime.getRuntime().exec("ipconfig/all");
            BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
            File outputFile = new File("/home/elie-m/NetBeansProjects/CMMAC/web/output.txt");
            FileWriter outt= new FileWriter(outputFile);
            System.out.println("MAC ADDRESS:\n");
            while ((s = stdInput.readLine()) != null) {

        Scanner par = new Scanner(s).useDelimiter("      Link encap:Ethernet  HWaddr ");
        if(s.startsWith("eth0"))
        {
        while(par.hasNext()){
        uno=par.next();
            des=par.next();
                outt.write(des);
                    }
        par.close();
        }

            }
            System.exit(0);
        }
        catch (IOException e) {
            System.out.println("exception happened - here's what I know: ");
            e.printStackTrace();
            System.exit(-1);
        }
    }
    @Override
public void stop() {}

}

when I launch the jsp page I get this error:

Reading certificates from 1580 http://localhost:8080/CMMAC/localfile.jar|/home/elie-m/.java/deployment/cache/6.0/18/57db752-3f3326e8.idx   
java.lang.NoClassDefFoundError:  localfile (wrong name: locf/localfile)     at 
java.lang.ClassLoader.defineClass1(Native Method)       at 
java.lang.ClassLoader.defineClass(ClassLoader.java:621)     at 
java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)     at 
java.net.URLClassLoader.defineClass(URLClassLoader.java:260)    at 
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)     at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at  
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at
java.lang.reflect.Method.invoke(Method.java:597)    at          
sun.plugin2.applet.Plugin2ClassLoader.defineClassHelper(Plugin2ClassLoader.java:694)  
        at  
sun.plugin2.applet.Plugin2ClassLoader.access$400(Plugin2ClassLoader.java:63)    at 
sun.plugin2.applet.Plugin2ClassLoader$2.run(Plugin2ClassLoader.java:671)    at 
java.security.AccessController.doPrivileged(Native Method)      at     
sun.plugin2.applet.Plugin2ClassLoader.findClassHelper(Plugin2ClassLoader.java:633)      at
sun.plugin2.applet.Applet2ClassLoader.findClass(Applet2ClassLoader.java:100)    at
java.lang.ClassLoader.loadClass(ClassLoader.java:307)       at 
java.lang.ClassLoader.loadClass(ClassLoader.java:252)       at 
sun.plugin2.applet.Plugin2ClassLoader.loadCode(Plugin2ClassLoader.java:433)     at 
sun.plugin2.applet.Plugin2Manager.createApplet(Plugin2Manager.java:2880)    at 
sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Plugin2Manager.java:1397) at
java.lang.Thread.run(Thread.java:619)
Exception:java.lang.NoClassDefFoundError: localfile (wrong name: locf/localfile)

This error occurs after I accept the permission question to use the applet.

I don't know where to put the .jar and the .class files so the client can read use the applet, and I can't even get around the error for 2 weeks of sea开发者_C百科rching now. I can give the whole directories folders/files structure in the project if needed. Just ask what do you need and I'll paste it here.

The jar is signed and the class is compiled, but it can't seem to find the applet's class that I need to run. I have the jar and class files into both WEB-INF/classes/locf/ and the build/web/ folders. and I have them also in the other web folder, the one in the same directory as build.

Operating system is linux ubuntu 9.10.


I've never run an applet from a JSP, but I see your Applet is in a package named locf. The error java.lang.NoClassDefFoundError: localfile (wrong name: locf/localfile) suggests that the JAR should reflect that directory structure. Referring to the tutorial, I'd expect something like this:

<applet
  code="locf.localfile"
  archive="localfile.jar"
  width="150" height="150">
</applet>

It might help to see the result of jar tf localfile.jar.

Also, class names conventionally use CamelCase, e.g. LocalFile.


You have to put the jar in the path your specifying with the archive param. Or change the archive param to match where you are hosting the applet jar.

From your code above the applet jar should be sitting on the Web root. Its fine if its not there you just need to adjust your params to point to the jar.

You can use the codebase parameter to specify the directory path if you want to leave the archive as just localfile.jar.

Here is an example.

Your JSP is located here

<WebRoot>//myJspFolder/myjsp.jsp

Your Jar is located Here

<WebRoot>//myAppletFolder/localfile.jar

Your applet params would be

 <param name="code" value="locf.localfile.class" />
 <param name="codebase" value="/myAppletFolder/" />
 <param name="archive" value="localfile.jar">

Or without using the codebase param

 <param name="code" value="locf.localfile.class" />
 <param name="archive" value="/myAppletFolder/localfile.jar">

The codebase param is useful if your loading multiple jars. You can use the codebase to supply the common portion of the path to each jar. I can give an example of that but I dont want to create clutter.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜