简体   繁体   English

关于JSP和SIgned Applet

[英]About JSP and SIgned applets

Here's the JSP page applet tags: 这是JSP页面applet标签:

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

Applet Code is: Applet代码为:

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: 当我启动jsp页面时,出现此错误:

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 searching now. 我不知道将.jar和.class文件放在何处,以便客户端可以使用applet进行读取,现在搜索2周甚至无法解决该错误。 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. 该jar已签名并且该类已编译,但似乎找不到我需要运行的applet的类。 I have the jar and class files into both WEB-INF/classes/locf/ and the build/web/ folders. 我将jar和class文件放入WEB-INF / classes / locf /和build / web /文件夹中。 and I have them also in the other web folder, the one in the same directory as build. 我也将它们放在另一个Web文件夹中,即与build相同的目录中。

Operating system is linux ubuntu 9.10. 操作系统是linux ubuntu 9.10。

I've never run an applet from a JSP, but I see your Applet is in a package named locf . 我从未从JSP运行applet,但是我看到您的Applet在名为locf的程序包中。 The error java.lang.NoClassDefFoundError: localfile (wrong name: locf/localfile) suggests that the JAR should reflect that directory structure. 错误java.lang.NoClassDefFoundError: localfile (wrong name: locf/localfile)表明JAR应该反映该目录结构。 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 . 查看jar tf localfile.jar的结果可能会有所帮助。

Also, class names conventionally use CamelCase , eg LocalFile . 同样,类名通常使用CamelCase ,例如LocalFile

You have to put the jar in the path your specifying with the archive param. 您必须将jar放在使用归档参数指定的路径中。 Or change the archive param to match where you are hosting the applet jar. 或更改存档参数以匹配您托管小程序jar的位置。

From your code above the applet jar should be sitting on the Web root. 从您的代码上方,小程序jar应该位于Web根目录上。 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. 如果要将存档仅保留为localfile.jar,则可以使用codebase参数指定目录路径。

Here is an example. 这是一个例子。

Your JSP is located here 您的JSP位于此处

<WebRoot>//myJspFolder/myjsp.jsp

Your Jar is located Here 您的Jar位于此处

<WebRoot>//myAppletFolder/localfile.jar

Your applet params would be 您的applet参数将是

 <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. 如果您加载多个jar,则代码库参数非常有用。 You can use the codebase to supply the common portion of the path to each jar. 您可以使用代码库为每个jar提供路径的公共部分。 I can give an example of that but I dont want to create clutter. 我可以举一个例子,但我不想造成混乱。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM