Solved

Security Exception: checkwrite:FILENAME

Posted on 1998-08-26
3
169 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This video teaches viewers about errors in exception handling.
Suggested Courses

710 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