aspose file tools*
The moose likes Applets and the fly likes Using Java to provide file write features to Javascript to emulate DB activity Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Applets
Bookmark "Using Java to provide file write features to Javascript to emulate DB activity" Watch "Using Java to provide file write features to Javascript to emulate DB activity" New topic
Author

Using Java to provide file write features to Javascript to emulate DB activity

Scott Dinwiddie
Greenhorn

Joined: Aug 22, 2012
Posts: 3
I am working on creating a Java stub to give write access via Javascript calls. I only need write access to a single text file that will serve as my data repository. This is going to be used to teach database interactivity through Javascript without requiring an SQL server or using the new HTML5 local database. Thank you for any assistance/suggestions.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 13884
    
  10

Welcome to the Ranch.

What exactly is your question? Can you explain in more detail what exactly you're looking for?


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Scott Dinwiddie
Greenhorn

Joined: Aug 22, 2012
Posts: 3
Javascript cannot write to localhost files (txt file in this case). I can get it to perform the write to file using ActiveX (got it working in IE currently), however, I am trying to figure out how to achieve this for Firefox/Chrome since they don't recognize ActiveX objects. I am taking the approach of creating a Java applet/whatever that can be called from javascript and passed the data to write to the .txt file creating a window for local file writing for Javascript to work through in Firefox and Chrome. I suppose my question would be, what would be the most effective way to provide file write capabilities to Javascript? I am looking at using what I refer to as a "Java Stub" to achieve this for Chrome and Firefox since I can use an ActiveX object to do it in IE. Thank you.

Edit: I am aware that applets are sandboxed via the JVM, however, it has occurred to me to attempt to call the applet from Javascript passing the data to be written to the applet, then calling a local jar file from the applet and relaying the data to the local jar file in hopes of stepping out of the sandbox for the applet.

The end goal is to emulate database access with Javascript without requiring a database server and keeping on the localhost for learning purposes.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18155
    
    8

It is possible for Javascript to call public methods in an applet which is loaded in the same page. And it is possible for the applet to update files on the local machine, if it is a signed applet.

However I have no idea what

calling a local jar file from the applet and relaying the data to the local jar file


means. A jar file is just a container for classes and other resources, so you can't "call" it and "relaying data" to it also doesn't make sense. At any rate, whatever you meant by that, it sounds a lot more cumbersome than just writing to a file.
Jayesh A Lalwani
Bartender

Joined: Jan 17, 2008
Posts: 2066
    
  22

Whaa?? You are teaching peoplehow to make Javascript interact with a local database? Why? Who on earth does that?

Scott Dinwiddie
Greenhorn

Joined: Aug 22, 2012
Posts: 3
I'll dig into the signed applets topic and take that approach. Thanks Paul.


It's not teaching people to use Javascript to access local databases. It's removing the database aspect and EMULATING database transactions. A JS API is what will access the text file that will serve as a data repository on the localhost side so those learning only have to worry about coding the JS side and make calls to the API to read/write data in the text file. Just a workaround to separate the database 'layer' in order to focus on the JS code for database access. It's a step for beginners to get a handle on coding JS without having to deal with the actual database transactions, which is in the next level of classes.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Using Java to provide file write features to Javascript to emulate DB activity
 
Similar Threads
is it possible to include external javascrip file into ear file using NetBean 5.5.1?
Connecting Exel file to servers Acess DB file remotely
Converting javaScript variable to java
GWT in Action:Qurie about Java Script
Creating Text File Using Java script!!