Page 1 of 2 12 LastLast
Results 1 to 20 of 28
  1. #1
    lena is offline Member
    Join Date
    Apr 2012
    Posts
    14
    Rep Power
    0

    Default applet connect to server problem

    hi all
    i have applet that i want to connect to the server when i run the applet from the appletviewer the applet connect to the server ,but when i run the applet from web browser i have the following exception
    java.security.AccessControlException: access denied ("java.net.SocketPermission" "127.0.0.1:3000" "connect,resolve")
    even i give the applet the folllowing permission
    grant{
    permission java.security.SocketPermission "127.0.0.1:3000" "connect,accept,listen,resolve";
    };

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,620
    Rep Power
    25

    Default Re: applet connect to server problem

    Was this posted on another forum? Were answers given there on how to create a .java.policy file to give an applet permissions?
    See http://www.daniweb.com/software-deve.../420906/applet

    Please describe completely how you are executing the applet.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    lena is offline Member
    Join Date
    Apr 2012
    Posts
    14
    Rep Power
    0

    Default Re: applet connect to server problem

    yes it was
    i first run the server then i open the html page and click on the button to connect to server

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,620
    Rep Power
    25

    Default Re: applet connect to server problem

    Please explain in more detail. There are many ways to open an html page: For example from a local file in a browser. What is the URL that is used to open the file? What does the html page look like
    When is the server started? What kind of server?
    If you don't understand my response, don't ignore it, ask a question.

  5. #5
    lena is offline Member
    Join Date
    Apr 2012
    Posts
    14
    Rep Power
    0

    Default Re: applet connect to server problem

    here is the server code
    Java Code:
    public class server {
    
      public server() {
        try{
    
          ServerSocket server=new ServerSocket(3000);
    while(true)
    
    {
      Socket client=server.accept();
    ClientServiceThread cli=new ClientServiceThread(client);
    cli.start();
    
    }
        }
        catch(Exception e)
        {
    
        }
      }
      public static void main(String[] args) {
        server server1 = new server();
      }
      class ClientServiceThread extends Thread{
       Socket clientsocket;
       ClientServiceThread(Socket s){
         clientsocket=s;
        }
         public void run(){
           try{  String url="jdbc:odbc:record";
                 Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                 Connection con=DriverManager.getConnection(url,"","");
                 String str="";
                 String acc="";
                 boolean found=false;
                 Statement stmt=con.createStatement();
                 DataInputStream in=new DataInputStream(clientsocket.getInputStream());
                   DataOutputStream out=new DataOutputStream(clientsocket.getOutputStream());
                   String k=in.readUTF().toString() ;
                   System.out.println(k);
                     StringTokenizer st=new StringTokenizer(k,"#");
                     String username=st.nextToken();
                     String pass=st.nextToken();
    
            ResultSet record=stmt.executeQuery("Select * from username");
            while(record.next())
            {
             if((record.getString("username").compareTo(username))==0)
              {
                if ((record.getString("password").compareTo(pass))==0)
                  {
                  str=record.getString("privilage").toString();
                  acc=record.getString("access");
                  found=true;
              } }}
              if (found==false)
            out.writeUTF("notfound");
              else{
                String u=str+"%"+acc;
           out.writeUTF(u);
    }
    }
    and here is the applet code
    try{//System.out.println(System.getProperties().getProperty("user.home"))
    
        Socket v=new Socket("127.0.0.1",3000);
        SecurityManager v1=new  SecurityManager();
        v1.checkAccept("127.0.1", 3000);
    v1.checkConnect("127.0.0.1", 3000);
        DataInputStream in=new DataInputStream(v.getInputStream());
        DataOutputStream out=new DataOutputStream(v.getOutputStream());
        out.writeUTF("hello");
      
        // TODO add your handling code here:
        }                                        
    catch(Exception e){
       System.out.println(e); }
    and here is the html page
    <html>
    <head>
    <title>Test page for launching the applet via JNLP</title>
    </head>
    <body>
    <h3>Test page for launching the applet via JNLP</h3>
    <applet code="NewJApplet1" width="300" height="300">
    <param name="jnlp_href" value="launch.jnlp"/>
    </applet>
    </body>
    </html>
    do you need any thing else and thank you for your help
    Last edited by Norm; 04-19-2012 at 03:29 PM.

  6. #6
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,620
    Rep Power
    25

    Default Re: applet connect to server problem

    Please list the steps you do to execute the applet. The posted code does not tell me what you do.
    What programs do you open? What do you type into those program's input boxes? etc

    launching the applet via JNLP
    For example what does the above mean? Where is the jnlp file?
    Last edited by Norm; 04-19-2012 at 03:30 PM.
    If you don't understand my response, don't ignore it, ask a question.

  7. #7
    lena is offline Member
    Join Date
    Apr 2012
    Posts
    14
    Rep Power
    0

    Default Re: applet connect to server problem

    i put my applet in a folder named pro and here is the path for the html page that contain the code f:/pro/dist/launch.html and i click on the launch.html and here is the url
    F:\pro\dist\launch.html and it is opend
    i have inside the dist folder a file named launch.jnlp and here is the code of it
    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <jnlp href="launch.jnlp" spec="1.0+">
    <information>
    <title>pro</title>
    <vendor>ali</vendor>
    <homepage href=""/>
    <description>pro</description>
    <description kind="short">pro</description>


    </information>
    <update check="always"/>

    <resources>
    <j2se java-vm-args="-Djava.security.policy=applet.policy" version="1.7+"/>
    <jar href="pro.jar" main="true"/>


    </resources>
    <applet-desc height="300" main-class="NewJApplet1" name="pro" width="300">

    </applet-desc>
    </jnlp>
    Last edited by lena; 04-19-2012 at 03:39 PM.

  8. #8
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,620
    Rep Power
    25

    Default Re: applet connect to server problem

    What about the reference to a jnlp file? Does the launch.html file contain what was posted in post#5?
    Applets loaded from a local file require permission to connect to a socket. Creating a policy file to give permission was discussed in the link in post#2. Have you read that?

    If the applet class files are in pro and the html file is in dist, how does the browser get the applet classes? The html does not refer to the pro folder? Your description does not make sense.
    Last edited by Norm; 04-19-2012 at 03:42 PM.
    If you don't understand my response, don't ignore it, ask a question.

  9. #9
    lena is offline Member
    Join Date
    Apr 2012
    Posts
    14
    Rep Power
    0

    Default Re: applet connect to server problem

    the pro.jnlp are in the dist folder
    so what can id to make it sence and work????

  10. #10
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,620
    Rep Power
    25

    Default Re: applet connect to server problem

    You still have not told me all the details of how you are executing the applet. You have said NOTHING about a pro.jnlp file!!!

    Please post ALL the details on how you are executing the applet. List all of the files involved and all the programs.

    When I execute an applet from a local html file there is only the browser and three files involved, nothing more: the html, the class files and the .java.policy file.
    If you don't understand my response, don't ignore it, ask a question.

  11. #11
    lena is offline Member
    Join Date
    Apr 2012
    Posts
    14
    Rep Power
    0

    Default Re: applet connect to server problem

    applet connect to server problem-x.jpgi will send you a photo that indicate all the folders exists
    Last edited by lena; 04-19-2012 at 05:34 PM.

  12. #12
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,620
    Rep Power
    25

    Default Re: applet connect to server problem

    The names of folders are not needed.

    It is the files that are used and their contents that are important.
    If you don't understand my response, don't ignore it, ask a question.

  13. #13
    lena is offline Member
    Join Date
    Apr 2012
    Posts
    14
    Rep Power
    0

    Default Re: applet connect to server problem

    first thank you for your answer second do you have any way to make me connect to the server i need it very much you just tell me what to do ?

  14. #14
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,620
    Rep Power
    25

    Default Re: applet connect to server problem

    That was described on the other forum. Get the link from post#2
    If you don't understand my response, don't ignore it, ask a question.

  15. #15
    lena is offline Member
    Join Date
    Apr 2012
    Posts
    14
    Rep Power
    0

    Default Re: applet connect to server problem

    i do all that and still not working

  16. #16
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,620
    Rep Power
    25

    Default Re: applet connect to server problem

    Recheck that you have done what was suggested. For example where is the policy file and what is its filename?
    If you don't understand my response, don't ignore it, ask a question.

  17. #17
    lena is offline Member
    Join Date
    Apr 2012
    Posts
    14
    Rep Power
    0

    Default Re: applet connect to server problem

    the policy file in f:/pro/applet.policy and it is also located in the home directory and file name applet.policy

  18. #18
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,620
    Rep Power
    25

    Default Re: applet connect to server problem

    Reread what I posted. I NEVER said to use that name.
    If you don't understand my response, don't ignore it, ask a question.

  19. #19
    lena is offline Member
    Join Date
    Apr 2012
    Posts
    14
    Rep Power
    0

    Default Re: applet connect to server problem

    why i cannot name it applet.policy i donot understand

  20. #20
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,620
    Rep Power
    25

    Default Re: applet connect to server problem

    What name did I say to use 3 times in the other thread?
    If you don't understand my response, don't ignore it, ask a question.

Page 1 of 2 12 LastLast

Similar Threads

  1. Applet doesn't connect to server over internet
    By mjgood91 in forum Networking
    Replies: 1
    Last Post: 04-28-2012, 05:44 AM
  2. Problem Java Applet Button Connects to a Server
    By francojava1 in forum Java Applets
    Replies: 3
    Last Post: 09-09-2010, 08:48 PM
  3. Connect to SQL Server
    By ddatta8 in forum JDBC
    Replies: 2
    Last Post: 03-08-2010, 05:28 PM
  4. Problem connect to SQL Server
    By Crisanto in forum Eclipse
    Replies: 1
    Last Post: 12-02-2008, 01:13 AM
  5. connect two applet
    By dg_iiita in forum Java Applets
    Replies: 0
    Last Post: 02-15-2008, 02:59 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •