Can we find the file on the client computer using the applet?

I am a PHP developer. I have a requirement that there will be a specific file on the client computer, and if this file exists, then the user will be able to enter the website. I can get the existence of the file using the code below:

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;
    }  
}

but how can I implement this in my project and send this response to the server so that the end user can log in or not.

+5
source share
3 answers

The applet of my Question is 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) {
}
}

,    javac AppletFileSearch.java   , jar    jar cvf AppletFileSearch.jar AppletFileSearch.class ,    keytool -genkey -alias AppletFileSearch -validity 365 URL 10 11 ( , , , : http://www.developer.com/java/other/article.php/3303561/Creating-a-Trusted-Applet-with-Local-File-System-Access-Rights.htm).Again    jarsigner AppletFileSearch.jar AppletFileSearch , . , , .

html-, :

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

html AppletFileSearch.html AppletFileSearch.html AppletFileSearch.jar (, apache). .

+4

, , , . , .

+1

Unsigned applets use client resources such as local file system, etc. To open this file, you will need to deploy the signed applet (and I think the user is warned that the applet will work with unlimited privileges). As an alternative approach, you could implement TSL / SSL client authentication .

0
source

All Articles