5

我是一名 PHP 开发人员。我要求客户端机器中有一个特定的文件,如果这个文件存在,那么用户就可以登录网站。我可以通过使用下面给出的代码来获取文件存在:

import java.io.File;
class FileSearchFirstOrder{
    public static void main(String args[])
    {
        boolean isExistP = false;
        File volumes = new File("/Volumes");
        File files[] = volumes.listFiles();
        for(File f: files)
        {
            //System.out.println("Current File -> " + f.getPath()); 
            isExistP = parseAllFiles(f.getPath());
            if(isExistP ==  true)
                break;
        }
        if(isExistP ==  true)
            System.out.println("I got the desire file Please continue.");
        else
            System.out.println("Sorry! I can not find the desire file Please try again leter:(");

    }

    public static boolean parseAllFiles(String parentDirectory)
    { 
        boolean isExistPC = false;
        try
        {
            File[] filesInDirectory = new File(parentDirectory).listFiles(); 
                for(File f : filesInDirectory)
            {  
                if (f.getName().toString().equals("key.txt"))
                {
                        //System.out.println("Current File ->" + f.getName()); 
                    isExistPC = true;
                }
                }  
        }
        catch(Exception e)
        {
        }
        return isExistPC;
    }  
}

但是我如何在我的项目中实现这一点并将这个响应发送到服务器,以便最终用户能够登录或不登录。

4

3 回答 3

4

The applet of my Question is in below:

import java.io.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import javax.swing.*;
import javax.swing.border.*;

public class AppletFileSearch extends JApplet implements ActionListener
{
 private JPanel pane = null;
 public void init() 
 {
    try{
        jbInit();
    }
    catch(Exception e) {
        e.printStackTrace();
    }
}
public boolean parseAllFiles(String parentDirectory)
{ 
    boolean isExistPC = false;
    try
    {
        File[] filesInDirectory = new File(parentDirectory).listFiles(); 
            for(File f : filesInDirectory)
        {  
            if (f.getName().toString().equals("key.txt"))
            {
                isExistPC = true;
            }
        }  
    }
    catch(Exception e){}
    return isExistPC;
}  
 private void jbInit() throws Exception
 {  
    boolean isExistP = false;
    File files[] = File.listRoots();
    for(File f: files)
    {
        isExistP = parseAllFiles(f.getPath());
        if(isExistP ==  true)
            break;
    }
    if(isExistP ==  true)
    {
    pane = new JPanel();
        pane.setBounds(new Rectangle(0, 0, 500, 35));
        pane.setLayout(null);
        pane.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED));
        pane.setBackground(new Color(0, 255,0));
        setContentPane(pane);
    }
    else
    {
        pane = new JPanel();
        pane.setBounds(new Rectangle(0, 0, 500, 35));
        pane.setLayout(null);
        pane.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED));
        pane.setBackground(new Color(255, 0, 0));
        setContentPane(pane);
    }
 }
 public void actionPerformed(ActionEvent e) {
}
}

Now compile this source using javac AppletFileSearch.java in command prompt then make it jar file using the command jar cvf AppletFileSearch.jar AppletFileSearch.class After that you have to make key certificate by using the command keytool -genkey -alias AppletFileSearch -validity 365 There will 10 or 11 steps (that will take password, first name, last name example is given in the url: http://www.developer.com/java/other/article.php/3303561/Creating-a-Trusted-Applet-with-Local-File-System-Access-Rights.htm).Again use the command for final signature jarsigner AppletFileSearch.jar AppletFileSearch There will be a prompt for asking password which you gave previous. If you give correct password the there will be a message the signer certificate will expire within six months.

After making this steps you have make a html page and the code will be like that:

<html>
<title>Run Applet</title>
</head>
<body>
<applet code="AppletFileSearch.class" archive="AppletFileSearch.jar"
       width=325 height=325></applet>
</body>
</html

and save this html file as AppletFileSearch.html and keep both the files AppletFileSearch.html and AppletFileSearch.jar in the server(like apache). And run from the browser and lets enjoy.

于 2013-02-27T06:37:40.357 回答
1

应该能够通过一个小程序,更具体地说,一个签名的小程序来做你需要的事情。教程应该为您指明正确的方向,以便您可以让您的小程序访问用户的本地文件系统。

于 2013-02-25T06:44:01.813 回答
0

未签名的小程序访问客户端资源,例如本地文件系统等。为了打开该文件,您需要部署一个签名的小程序(我认为用户被警告该小程序将以不受限制的权限运行)。作为替代方法,您可以改为实现TSL/SSL 客户端身份验证。

于 2013-02-25T06:47:02.730 回答