Solved

Security Exception: checkwrite:FILENAME

Posted on 1998-08-26
3
167 Views
Last Modified: 2013-12-29
I have my main code called "oracle_supply.java", it calls
Create_Html.java (class) like this:

if ("Create HTML".equals(s)){
         new Create_Htmls();
}

In Create_Htmls, all i'm tring to do is open a file on the
server and write text to it like this:

public class Create_Htmls{
   static String buf1=null;
   static PrintWriter output = null;
   static String in = "test.dat";

   public Create_Htmls() {
      System.out.println ("Now in Create_Htmls code");
      try {
        output = new PrintWriter(new FileWriter(in));
      } catch (Exception e) {
      System.out.println("Couldn't create output file");
      System.exit(1);
      }

      output.println("This is test.dat");

What happens is nothing, in the java console window
I get this:

Now in Create_Htmls code
# Security Exception: checkwrite:test.dat

Now if on the server, I say "java Create_Htmls" it
creates the test.dat file fine, but NOT when I call
it from "oracle_supply".

I have other code that I have written that does similiar
things, and it works fine. But I missing something
in this project. Any suggestions?
Basically, i'm running an applet, and from that applet,
i'm calling another piece of code that will create a
file on the server.  Hum... on further review, I have just
remembered that in my other code writing files on the
server, I used a socket. Is that what I need to do here?
I will try that (I know it works) while I wait for an answer.
So new question is can I create a file on my server from
an applet with out using sockets?

Thanx!
Don
0
Comment
Question by:afsac
  • 2
3 Comments
 

Author Comment

by:afsac
ID: 1222597
Edited text of question
0
 
LVL 8

Accepted Solution

by:
diakov earned 250 total points
ID: 1222598
Hi,

Let's first clear some basics that I sence may be are not very clear to you.
- First the applet is a piece of code, transported through the net via the HTTP protocol to the client machine and run there.

- The applet runs in the browser's JVM and is very restricted on usage of the local client machine resources.

- The only place it could contact without a security exception is the web server it originates from.

- Apparently, when you run your 'file creating code' from the applet, it loads in the local machine and tries to create a file on it. Which in case of applet come from a server, will lead to the described security exception.

- What you need to do is to write an apllication that runs on the server and anticipates calls from the applets on the client machines connected to the web server there.

- There are several ways to do this:
  - Using sockets. There again are several ways:
   . simple socket communication. the server program listens to a port on the server machine, and the client program (the applet) opens a socket to this port. There quite many examples on the net, I can send you a chat application if you want.
   . some middleware, like JavaRMI, that hides the socket communication from you and provides classes for doing this quite transparently. For example, on the applet, you can create an Java object, which actually is on the server, but your code uses it like it is in the applet itself.

Problem with sockets is that if you have a firewall, it disallows the direct socket communication except on some legal ports like the ftp - 21, web server - 80, telnet - 23, etc. And it is a big problem, because a lot of companies use corporate firewalls.

 - using HTTP/CGI tunneling. You can write a server application which is an extension of the web server. Some web servers allow scripting, like MSIIE, Oracle web server, etc. Some of them have extensions for Java, and you can write so called servlets.


I suggest the HTTP/CGI, which differs in form according to the scripting language or CGI programs that are used on the web server.

So the scenario is:

Your applet loads, and opens the URL where the server script processes the request for creating a file. After receiving the data for the file, the server object creates a file locally on the server, and returns result.

If you have more comments, please send them.

Cheers,
  Nikolay


0
 

Author Comment

by:afsac
ID: 1222599
Nikolay,
     I have it working now by using a socket.  At this time, we don't
have a firewall, but probably will in the future.  The Java code is loaded
from my server, and the file to be created is on the same server. So
the Socket thing is working for me for now.

     Thank you for your quick response.

Don
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
split53 challenge 7 96
what is a "java.lang.System Property"   ? 20 67
ejb on wildfly 5 20
Java: anonymous class 4 20
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question