Using Swing applet to write data to file on SERVER

Hello,
I'm in the process of writing an applet using Swing (SDK v1.4.2). Here's the deal. The JApplet calls a JPanel, which will be used by customers on my site to enter data. I'm adding a <Save> button to the "form" which is supposed to write data to a file on the server (in order to preserve the customer's preferences).
Please note that I am NOT attempting to write data to the customer's hard disk. That requires digital certificates, etc. which I am trying to avoid for now.
Instead, I am using the URL class to access the file:
URL page = new URL("http://www.whatever.com/mycustomers/preferences.txt")
I then use the URLConnection class to establish the connection:
URLConnection conn = this.page.openConnection();
conn.setDoInput(true);
conn.setDoOutput(true);
conn.connect();
etc...
I've created a text file (preferences.txt) on my web site. Using the classes InputStreamReader, BufferedStreamReader, and StringBuffer, I can successfully read the file into a JOptionPane in my applet.
The problem comes when I try to write data TO this file. I know the file exists because the applet can read it. I've set the permissions on the file to 666. I've got all of the appropriate syntax within a try statment that catches an IOException. I also have JOptionPanes all over the place to let me know where the program is. I've tried different combinations of output streams like BufferedWriter, BufferedOutputStream, StringWriter, but the file does not get updated. When the applet runs, it does not throw any exceptions, not even when I change the URL from "HTTP://www.whatever.com/prefs.txt" to "HTTP:/www.whatever.com/prefs.txt" (only one slash on HTTP, shouldn't I get a MalformedURLException?)
I apologize for all the background, but I thought you might need it. The bottom line is:
1) Can an applet write to a file on a remote server (not local hard disk)?
2) If so, what (if any) caveats are there?
3) Is there a way to check for file existence or be able to create a new file?
4) I'm using the HTTP protocol - is there some restriction that prevents an applet from writing to a file using that protocol? If so, is there a workaround?
5) Assuming that creating/writing a file using the method I've described is possible, what would be the appropriate output streams to use? (Currently, I'm using OutputStreamWriter with BufferedWriter).
I've been struggling with this for a while. Any help/suggestions would be appreciated.
Thanks
P.S. I also posted this message on the Applet development forum, but I've received no response as of yet.

Http servers support PUT as a mechanism to upload data to a specified URL. Get on the other hand which is what most people are familiar with is how you retrieve that data. The basic URLConnection is an abstraction of the Http connection which can be used for GET and POST operations by default based on doInput(true|false).. If you which to use any of the http methods other than GET|POST you will have to cast the URLConnection to HttpURLConnection so you can gain access to the specific Http functionaility that could not be abstracted.
Since you are using a hosting service the chances are that you won't be able to use HTTP PUT on their server. Most servers do not support HTTP PUT without configuring them todo so. Now Apache allows localized config through the .htacess file. It might be possible (keep in mind I am not an apache expert) to configure a particular directory to allow HTTP PUT using this .htacess file it may not be possible. You will have to consult the Apache web server documentation for that answer.
But regardless you can use the HttpURLConnection and the PUT method to send data from your applet to the server. In fact that is the preferred way to do this. If you can not configure your web server to support that method then you will have to develop a Servlet to do it. A servlet has several methods such as doGet(), doPost(), and doPut(). You would override the doPut() method get the URI path create a file and a FileOutputStream to that file, get from the request the inputstream, possibly skip the http headers, and then write byte for byte the incoming data to your OutputStream until you reach the end at which point you would close the OutputStream and send an Http Response of some sort. Typically in HTTP it would be 200 OK plus some web content. You content can be empty so long as your applet recognizes that is what it should expect...
And away you go...

Similar Messages

  • How to write data to file Java ME cldc 1.1 midp 2.0?

    I newly in java me, please help me.
    I make project in NetBeans 7.0.1. and use cldc 1.1 midp 2.0.
    I want to write data to the file.
    How can I do it?
    I try to use FileOutputStream. But it don't exists in java.io
    NetBeans shows me only this list of classes and interfaces in java.io:
    ByteArrayInputStream, ByteArrayOutputStream, DataInput, DataInputStream, DataOutput, DataOutputStream, InputStream, InputStreamReader, OutputStream, OutputStreamWriter, PrintStream, Reader, Writer.
    Why it so short?
    And how I can write data to file?
    Data can be array of bytes (byte[]) or Object it better.

    You must use JSR 75: FileConnection. Please check the following article "Getting Started with the FileConnection APIs":
    http://developers.sun.com/mobility/apis/articles/fileconnection/
    Be sure to use FileSystemRegistry.listRoots().
    And welcome to Java ME development. :)

  • Using swing applet in IE

    Dear,
    Is there any way to use swing applet in IE.
    Thanks,

    If you are trying to make your code workable with Microsoft's VM, then I'd say you are looking for trouble. That VM's version is 1.1.4, if I'm not mistaken.
    Better stick to the JRE 1.4 with the plugin.

  • Data Acquisition - using local variables to write data to a file

    Hello,
    I am running a Data Acquisition vi (currently in LabVIEW 7.1 but soon to be updated to 8.2) that collects ~100 parameters of data from several sources contained in a while loop. The current configuration (which I did not write) uses very few subVIs and writes to ~100 local variables to store each parameter. It then reads all the local variables and builds an array of all the strings, converts then to a spreadsheet string, then uses the write characters to file function to append to a datafile. I am trying to clean things up and have came up with subVIs to collect the data from the following sources:
    8 serial port sources collecting btwn 8 and 20 parameters each
    ~15 thermocouple readings
    ~10 analog inputs
    ~20 parameters read off an ARINC 429 bus.
    I have come up with a subVI to read each of the sources and have placed the subVIs in the while loop. Each subVI outputs the data that it collects in array or cluster form. I was wondering how best to write each parameter to a CSV file at between 1 and 10 Hz. Should I write each subVI output to a LV and then read them off as was done before (the difference being that I have reduced the # of LVs to ~10 vs >100?
    I should add that precise timing is not that important, so if all the subVIs are not collecting simultaneously (which I understand that they won't be), it does not really matter.
    Thanks.

    Hi jilla,
    jilla wrote:
    What I think that you are saying is to turn the outputs of the 4 subVIs into inputs of a 5th subVI that writes to the data file. Correct?
    Yes.  It may sound like a fine-point, but I beileve it's better to create a VI specifically for formatting data - in your example, 4 arrays IN, a single string OUT.  Then write the string to file as a seperate operation.  GUI-displayed data can go through a similar transformation, the four arrays wired to a subVI which builds output-structures specifically for display.  It's a beginner's mistake to put lots of individual controls and indicators on the screen when groups of them are naturally related (in an object-oriented sense.)  Use clusters to group related controls - this will keep the diagram much cleaner.
    One more question: at what point (either # of data points or frequency of data collection) does it become necessary to use queues? Thanks.
    Well, there's not really a clearly definable "point".  I'd say if your update-rate climbs above 100Hz, or you witness poor program or system performance, then it's time.  The scenario you've described is a fairly simple acquire/display&log loop - and simple is good.   Then-again people can't see/react-to updates faster than about 10Hz - so it doesn't make sense to sacrifice performance - if performance becomes an issue.
    Re: queues:  Queues are sometimes used to buffer data that's "produced" in one place and "consumed" in another.
    Here, if/when logging data, you're logging with every DAQ.  I wouldn't recommend using a queue to transport data from a "DAQ loop" to a "Logging-loop" - those functions can be in the same loop.  Should/could a queue be used to get data from a "DAQ loop" to update the GUI at a lower frequency?  Sure, but a Notifier might be a better choice.   Further, in the (simple?) program you've described, you might use a case structure (True/False) to only update FP indicators every "X" iterations - a simple solution that doesn't require Queues or Notifiers.
    Cheers!
    "Inside every large program is a small program struggling to get out." (attributed to Tony Hoare)

  • Attempting to write data to file, but getting error 200279

    I am having trouble when writing data to a file. About 10 seconds into the saving process, I get the error 200279. I have done some research on the topic, but am unable to corect my code. I believe I do not want to increase the buffer size, but would rather, I assume, read the data more frequently. The way I save my file is, before running the VI, I assign a location and name of the file (e.g. data.csv). The date and time is appended to the end of the actual file when the I begin to save the data (e.g. data_07-26-13_122615.csv). If the file does not exist, it creates a new file, then appends data to that file after every loop iteration. The reason I did it this way was so I do not have to worry about running out of memory, but apparently my code is flawed. 
    I will include a copy of the flawed section of my code. Any help would be greatly appreciated.
    Thanks.
    Solved!
    Go to Solution.
    Attachments:
    data_acquisition.vi ‏127 KB

    Your problem is that writing to disk is slow.  It is slow enough that it is causing your DAQ buffer to overflow and cause the error and loss of data.  What you need to do is implement a Producer/Consumer.  This will put the daq and the logging to disk in seperate loops.  This will allow the DAQ to run at the speed it needs to keep up with incoming samples and the writing to disk can run at whatever rate it can.  You send the DAQ data to the logging loop using a queue.
    You might also want to think about changing how you write to the file.  That VI is constantly opening and closing the file, which is a very slow process if you are doing it inside of a loop.
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

  • Cannot use SWING Applets!

    I tried to use Netscape 6.2 Browser with "Java(TM) Plug-in: Version 1.4.0" to start an swing applet. but what i got was an error in the java-Console. In the dokumentation i counld not find a hint to solve the problem.
    java-Consol error message:
    java.lang.IllegalArgumentException
         at sun.net.www.ParseUtil.decode(Unknown Source)
         at sun.net.www.protocol.file.Handler.openConnection(Unknown Source)
         at sun.plugin.net.protocol.file.Handler.openConnection(Unknown Source)
         at java.net.URL.openConnection(Unknown Source)
         at sun.applet.AppletPanel.getAccessControlContext(Unknown Source)
         at sun.applet.AppletPanel.getClassLoader(Unknown Source)
         at sun.applet.AppletPanel.createAppletThread(Unknown Source)
         at sun.applet.AppletPanel.init(Unknown Source)
         at sun.plugin.AppletViewer.appletInit(Unknown Source)
         at sun.plugin.viewer.LifeCycleManager.initAppletPanel(Unknown Source)
         at sun.plugin.viewer.WNetscapePluginObject$Initer.run(Unknown Source)
    HTML File for applet start:
    <!-- The following code is specified at the beginning of the <BODY> tag. -->
    <SCRIPT LANGUAGE="JavaScript"><!--
    var info = navigator.userAgent; var ns = false;
    var ie = (info.indexOf("MSIE") > 0 && _info.indexOf("Win") > 0
    && _info.indexOf("Windows 3.1") < 0);
    //--></SCRIPT>
    <COMMENT><SCRIPT LANGUAGE="JavaScript1.1"><!--
    var _ns = (navigator.appName.indexOf("Netscape") >= 0
    && ((_info.indexOf("Win") > 0 && _info.indexOf("Win16") < 0
    && java.lang.System.getProperty("os.version").indexOf("3.5") < 0)
    || _info.indexOf("Sun") > 0));
    //--></SCRIPT></COMMENT>
    <!-- The following code is repeated for each APPLET tag -->
    <SCRIPT LANGUAGE="JavaScript"><!--
    if (_ie == true) document.writeln('
    <OBJECT
    classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
    width="200" height="200" align="baseline"
    codebase="http://java.sun.com/products/plugin/1.4/jinstall-14-win32.cab#Version=1,4,0,mn">
    <NOEMBED><XMP>');
    else if (_ns == true) document.writeln('
    <EMBED
    type="application/x-java-applet;jpi-version=1.4" width="200" height="200"
    align="baseline" code="swingtest.swingtest.class" codebase="html/"
    model="models/HyaluronicAcid.xyz"
    pluginspage="http://java.sun.com/products/plugin/1.4/plugin-install.html">
    <NOEMBED><XMP>');
    //--></SCRIPT>
    <APPLET code="swingtest.swingtest.class" codebase="html/" align="baseline"
    width="200" height="200">
    </XMP>
    <PARAM NAME="java_code" VALUE="swingtest.swingtest.class">
    <PARAM NAME="java_codebase" VALUE="html/">
    <PARAM NAME="java_type" VALUE="application/x-java-applet;jpi-version=1.4">
    <PARAM NAME="model" VALUE="models/HyaluronicAcid.xyz">
    <PARAM NAME="scriptable" VALUE="true">
    No Java 2 SDK, Standard Edition v 1.4 support for APPLET!!
    </APPLET></NOEMBED></EMBED>
    </OBJECT>
    <!--
    <APPLET code="swingtest.swingtest.class" codebase="html/" align="baseline"
    width="200" height="200">
    <PARAM NAME="model" VALUE="models/HyaluronicAcid.xyz">
    No Java 2 SDK, Standard Edition v 1.4 support for APPLET!!
    </APPLET>
    -->

    Use the search bar to the left and you will find many things...
    Follow the link in the post below:
    http://forum.java.sun.com/thread.jspa?threadID=483984&messageID=2567249

  • Need info on using external tables load/write data

    Hi All,
    We are planning to load conversion/interface data using external tables feature available in the Oracle database.
    Also for outbound interfaces, we are planning to use the same feature to write data in the file system.
    If you have done similar exercise in any of your projects, please share sample code units. Also, let me know if there
    are any cons/limitations in this approach.
    Thanks,
    Balaji

    Please see old threads for similar discussion -- http://forums.oracle.com/forums/search.jspa?threadID=&q=external+AND+tables&objID=c3&dateRange=all&userID=&numResults=15&rankBy=10001
    Thanks,
    Hussein

  • I want to run my program with continuous aquisition and write data to file when a button is pressed and get the most recent samples from the DAQ board.

    This is an update to a question I asked earlier. I am still trying to solve the problem. I have included a zip file with a library file. The file to open in pj_pushbutton.vi. I have placed comments explaining the issues and problems in this vi and the subvi's.
    When I push my button to write the data to file I think it is writing the data that has already been stored in the buffer and writing to file all at once. I want the data that is taken from the DAQ board from the time that I press the Write File button. How do I do this?
    Attachments:
    pj_pushbutton.zip ‏692 KB

    Hi,
    1. In AI read, you need to set the Read/Search option to "Relative to End of Data".
    2. Next you should not start AI Read VI until you press the Write to File. I am attaching an example VI below. Please see if it helps.
    Regards,
    Sastry V
    applications Engineer
    National Instruments
    Attachments:
    MostRecentAcquiredData.vi ‏97 KB

  • Problem while using BCP utility for witing data in file

    hi all,
    I have a batch file in which I am using bcp command for reading data from MS SQL and writing it in delimiter file. Now there are some exceptions in MS SQL that while writing into file whenever it encounters new line character it switches to next line while writing and starts writing the rest of the data on next.
    Could you help me in getting rid of this problem. I wanted to replace the new line character with space.
    Thanks and regards
    Nitin

    Hi Dilip,
    Before going for any other table,
    As Kalnr is only one of the primary keys of table KEKO, You can try creating secondary index on KEKO, which might help in improving your report performance.
    Also, you can add more conditions in where clause if possible, which will also help in improving performance.
    Thansk,
    Archana

  • Write to text file without server side

    Hi,
    I need to write data into a text file for saving data from my
    flash movie, but I didn't have the possibility to use a
    server-side.
    Because my flash movies are stored on a CD and it must be
    compatible with Windows and MacOS.
    Is it possible to write data into a text file?
    If no, can I use a third party software? Which one?
    Regards
    YamNet

    A SharedObject might work for you. Otherwise, you'll need a
    'wrapper' app.
    Adobe's own Director works very well for this, and AIR would
    work as well.
    There are also a good number of 3rd party apps, such as Zinc
    and others.
    Dave -
    Head Developer
    http://www.blurredistinction.com
    Adobe Community Expert
    http://www.adobe.com/communities/experts/

  • Get data from file in server to client and vice versa

    after greeting
    i really didn't know how to use socket and serversocket to get data from file in the server and display it to client.
    also read file from client and save it to server.
    really i didn't know how to do it.
    really i want the reply as soon as possible

    You REALLY need to work through the Java networking tutorials:
    http://java.sun.com/docs/books/tutorial/networking/index.html

  • Desperately seeking help!! IE Crashes using Swing Applet

    Hi,
    I've created a grid applet using JTable and Swing in an applet. It runs great with data from a SQL database. I have at least 3 instances of the grid on the same page and other places on the site.
    However, Internet Explorer crashes frequently throwing an error "Unhandled exception at xxxxxxx in IExplore.exe (Beans.ocx).
    And the behavior is random and unpredictable.
    I've been desperately trying to look for help to fix this.
    Could someone please, please offer some suggestion?
    Thanks in advance,
    Anand.

    I agree. Try upgrading your plug-in version to 1.3.1. Keep in mind though that after 1.3.0, Sun changed where the plug-in looks for the root certificate. If you're using a Verisign or Thawte certificate, you shouldn't have any problems. If you're using your own certificate, you'll probably need to import it into the cacerts file in the lib/security directory under the installation directory of your jre.
    Hope this helps,
    Mark

  • Trying to write data to file (time from timestamp + velocity + temperatur​e)

    Hello all. I've received a considerable amount of help from many of you recently, and once again I'm seeking assistance.  Having spent the majority of my LabVIEW time dealing with GPIB and data aq boards, I'm still struggling with various aspects of serial communication.  I have been working on a .vi to both control and accept data from a Furness Micromanometer.  The last task is to write the data to a file.  Attached is a copy of the vi, as well as what the front panel looks like after a test, and the resulting data saved to disk.  Anyone have any suggestions on how I should change the formatting of the data, or do whatever else might be necessary, so that my laptop and the micromanometer will get along and play well together?
      Below is the data saved to the text file, as well as the front panel showing what SHOULD have been saved. See next posting for vi.
       @6      @6      @6      @6      @6      @6      @6               
    8:00:00 PM             
    8:00:00 PM  
    1:41:28 PM             
    8:00:00 PM  
    1:41:28 PM  
    1:41:37 PM?²-V     
    8:00:00 PM  
    1:41:28 PM  
    1:41:37 PM  
    1:41:47 PM?°£×
    =p¤     
    8:00:00 PM  
    1:41:28 PM  
    1:41:37 PM  
    1:41:47 PM  
    1:41:57 PM?éãS÷ÎÙ     
    8:00:00 PM  
    1:41:28 PM  
    1:41:37 PM  
    1:41:47 PM  
    1:41:57 PM  
    1:42:07 PM?ÿt¼j~ùÛ     
    8:00:00 PM  
    1:41:28 PM  
    1:41:37 PM  
    1:41:47 PM  
    1:41:57 PM  
    1:42:07 PM  
    1:42:17 PM?ûhr° Äœ     
    8:00:00 PM  
    1:41:28 PM  
    1:41:37 PM  
    1:41:47 PM  
    1:41:57 PM  
    1:42:07 PM  
    1:42:17 PM  
    1:42:27 PM?ÆéxÔýó¶      
    8:00:00 PM  
    1:41:28 PM  
    1:41:37 PM  
    1:41:47 PM  
    1:41:57 PM  
    1:42:07 PM  
    1:42:17 PM  
    1:42:27 PM  
    1:42:37 PM?ý‡+ J

    It looks like you have not formatted your data properly to save it. Can you post a bit of you code? It would be easier to advise you.
    Mike...
    PS: Where are you at with Corning? I spent about 2 yrs in Painted Post...
    Certified Professional Instructor
    Certified LabVIEW Architect
    LabVIEW Champion
    "... after all, He's not a tame lion..."
    Be thinking ahead and mark your dance card for NI Week 2015 now: TS 6139 - Object Oriented First Steps

  • How to use Swing html to parse a html file..

    I am currently working on a project in java.i need to read a Html file, extract the table tag along with its contents if it has a button embedded in it and replace it with another code..
    i tried it with Reg Ex in java but in vain.. Any help is great... I need an idea of how to use Html parser for this prob.. any examples will be fine..

    Run the program from command line, this way you will see the errors, if any.
    example.: java -jar theJarfile.jar
    I was successful in creating a comm application. I placed the win32com.dll in the same directory of my application jar file and all worked.
    I also extracted the comm.jar , and jar'd my app with the extracted comm files to make one jar.
    I also had a fileWriter() to get the clients jre path and my app would write the javax.properties file to the correct place.
    It took me severel weeks and late nights to accomplish this, but it was all necessary to be able to install only my app, and not a bunch of api's that were needed.

  • Problem with 6071E to write data on file?

    Hi,
    I would like to save my value from analog input of my 6071E card on a text file, I've only on channel selected but when I run my program I've an error.
    I'm in continuous mode but over than 10kHz and 10000 samples the program doesn't work, and I need to be at 100k or 1MHz.
    Thanks a lot
    Under labview 8.0
    Message Edited by drikc on 01-23-2007 06:18 AM
    Message Edited by drikc on 01-23-2007 06:18 AM
    Attachments:
    6071E test2.vi ‏122 KB
    stream to disk.JPG ‏39 KB
    error3.JPG ‏29 KB

    drikc,
    if the file-format is the only headache for you in this example, then the solution is very easy: Just replace all binary-functions from the file IO with appropiate ASCII-functions. Of course, you have to convert your data into string(s) first.
    Since ASCII files are very slow compared to binary and the conversion takes time as well, you have to benchmark if you achieve the performance you need with this mechanics....
    NorbertMessage Edited by Norbert B on 01-26-2007 02:08 AM
    CEO: What exactly is stopping us from doing this?
    Expert: Geometry
    Marketing Manager: Just ignore it.

Maybe you are looking for