Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Security Errors

 
rahul karwal
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ppl,
i am having problem when i run this applet its giving me a security Errors and saying errors such as permision denied to write to a file. What i am actually trying to here get user's name, last name, email address and write that to a file and want to send the file to the server... but connecting to server is still needed to be coded but i am having problem with creating a fils i dont know so can anyone please help me...
thanks

import java.io.*;
import java.io.File;
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import java.util.*;
public class myapplet extends Applet implements ActionListener,TextListener {
TextField fname;
Panel dpanal;
Label fnamelabel;
Label lnamelabel;
TextField lname ;
Label emaillabel;
TextField email;
Label space;
Label note;
Label fevent;
Checkbox firstevent;
Label sevent;
Checkbox secondevent;
Label tevent;
Checkbox thirdevent;
Label foevent;
Checkbox forthevent;
Label submitlabel;
Button submmitbutton;
String firstNameText="";
String secondNametext="";
String emailtext ="dumb";
public void init(){

dpanal = new Panel();
fnamelabel = new Label("Please Enter Your First Name");
fname = new TextField(10);
fname.addTextListener(this);
lnamelabel = new Label("Please Enter Your Last Name");
lname = new TextField(10);
lname.addTextListener(this);
emaillabel = new Label("Please Enter Your E-mail Address");
email = new TextField(10);
email.addTextListener(this);
space = new Label();
note = new Label("Please Click As Many Events You Are Interested In");
fevent = new Label("");
firstevent = new Checkbox("Baseball");
sevent = new Label("");
secondevent = new Checkbox("Cricket");
tevent = new Label("");
thirdevent = new Checkbox("Football");
foevent = new Label("");
forthevent = new Checkbox("Tennis");
submitlabel = new Label("");
Button submmitbutton = new Button("Submit");
submmitbutton.addActionListener(this);

dpanal.setLayout(new GridLayout(9,9));
dpanal.add(fnamelabel);
dpanal.add(fname);
dpanal.add(lnamelabel);
dpanal.add(lname);
dpanal.add(emaillabel);
dpanal.add(email);
dpanal.add(space);
dpanal.add(note);
dpanal.add(fevent);
dpanal.add(firstevent);
dpanal.add(sevent);
dpanal.add(secondevent);
dpanal.add(tevent);
dpanal.add(thirdevent);
dpanal.add(foevent);
dpanal.add(forthevent);
dpanal.add(submitlabel);
dpanal.add(submmitbutton);
submmitbutton.setBackground(Color.lightGray);
setBackground(Color.white);
add(dpanal);

}


public void actionPerformed(ActionEvent e) {

print();
clearTextfield();
createFile();


}

public void textValueChanged(TextEvent e){

firstNameText = fname.getText();
secondNametext = lname.getText();
emailtext = email.getText();
}

public void print(){

System.out.println(firstNameText);
System.out.println(secondNametext);
System.out.println(emailtext);
}

public void clearTextfield(){

fname.setText("");
lname.setText("");
email.setText("");
System.out.println("Text fields cleared");
}

public void createFile() {

File file = new File(emailtext);

try{

file.createNewFile();
}
catch(IOException e1){
System.out.println("error occured"+e1);
}


System.out.println("after create method");
boolean cheak= file.exists();
System.out.println(cheak);

}




}
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18166
53
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Java sandbox rules forbid unsigned applets from reading or writing files on the local computer - which is why the Nimda virus wasn't written in Java.
From what I've seen, in 99% of the cases, trying to produce a signed applet isn't worth the trouble. It's a LOT of trouble - especially since you have to do it 2 different ways. Do you REALLY need a local file? Especially when you're dealing with sensitive data like user names and passwords? You can create an HttpURLConnection, open an output stream and write to the server directly.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic