Security Exception in appletviewer

Hi,
      I have written an applet, which will recieve user name and password, from the client and send those information to my servlet, which is present under the same server.

      I am using URL object to connect with my servlet.

eg. URL u = new URL(MyIp:8080/servletpath/servlet?login=user&passwd=password);

When i run this applet with netscape navigator it works well, but while testing with appletviewer, throws an exception

java.net.PlainSocketImpl.available
etc.,

could any one tell me what is wrong.

the html is given below
<applet codebase="http://xxx.x.xx.x:8080/examples/servlets"  code="login.class" height=200 width=200></applet>

Thank you,
G Ramesh
rameshg21Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ravindra76Commented:

Hi rameshg21,



  You did n't mention your jdk version.
If it is java 2.0, the security exception will come and you did n't set the java.policy file it will come

Replace java.policy file with following text.

It will be in two locations

grant {
      // Allow everything for now
      permission java.security.AllPermission;
};

If it is not, give fill stacktrace of error

1. c:\jdkhome\jre\lib\security
2.c:\program files\javasoft\jre\1.2\lib\security.

Other wise do one thing.

Fine the all locations of java.policy file through find files options and replace the text with above.

Best of luck
0
rameshg21Author Commented:
Excellent!!! ravindra
Thanks,
G Ramesh
0
Ravindra76Commented:
Can i post answer?

If you want to accept the comment as answer, see on comment label.

Thank you
0
Ravindra76Commented:

 Hi rameshq21,

  The reason for your problem is new security model introduced introduced in java1.2 which is not present in previous versions of java.

  Now with grant all permissions, we again fallback to security less model.

 Now it is working.

 But in future, if you want more security, grant all permisions is not good.

You can override required permissions from default.

If you have no backup, keep it up with you



// Standard extensions get all permissions by default

grant codeBase "file:${java.home}/lib/ext/-" {
      permission java.security.AllPermission;
};

// default permissions granted to all domains

grant {
      // Allows any thread to stop itself using the java.lang.Thread.stop()
      // method that takes no argument.
      // Note that this permission is granted by default only to remain
      // backwards compatible.
      // It is strongly recommended that you either remove this permission
      // from this policy file or further restrict it to code sources
      // that you specify, because Thread.stop() is potentially unsafe.
      // See "http://java.sun.com/notes" for more information.
      permission java.lang.RuntimePermission "stopThread";

      // allows anyone to listen on un-privileged ports
      permission java.net.SocketPermission "localhost:1024-", "listen";

      // "standard" properies that can be read by anyone

      permission java.util.PropertyPermission "java.version", "read";
      permission java.util.PropertyPermission "java.vendor", "read";
      permission java.util.PropertyPermission "java.vendor.url", "read";
      permission java.util.PropertyPermission "java.class.version", "read";
      permission java.util.PropertyPermission "os.name", "read";
      permission java.util.PropertyPermission "os.version", "read";
      permission java.util.PropertyPermission "os.arch", "read";
      permission java.util.PropertyPermission "file.separator", "read";
      permission java.util.PropertyPermission "path.separator", "read";
      permission java.util.PropertyPermission "line.separator", "read";

      permission java.util.PropertyPermission "java.specification.version", "read";
      permission java.util.PropertyPermission "java.specification.vendor", "read";
      permission java.util.PropertyPermission "java.specification.name", "read";

      permission java.util.PropertyPermission "java.vm.specification.version", "read";
      permission java.util.PropertyPermission "java.vm.specification.vendor", "read";
      permission java.util.PropertyPermission "java.vm.specification.name", "read";
      permission java.util.PropertyPermission "java.vm.version", "read";
      permission java.util.PropertyPermission "java.vm.vendor", "read";
      permission java.util.PropertyPermission "java.vm.name", "read";
};


For you it is enough to change

      // allows anyone to listen on un-privileged ports
      permission java.net.SocketPermission "localhost:1024-", "listen";

this line

with

      // allows anyone to listen on un-privileged ports
      permission java.net.SocketPermission "localhost:1024-", "listen";

For this refer this URL

http://www.eurocom.od.ua/~sasha/books/java/JavaUnleashed_1.2/ch03/ch03.htm

if you add "accept","connect","resolve"
after listen in the above line, it will work.

You have to set port also. See the above link for full details

Best of luck


0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ravindra76Commented:
thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.