Applet write to file on server

Despite people's insistence that this is in the tutorial or faq, I find that it is not. Also, I have gotten conflicting information about this so I'd like to know the real answer. I want to have an applet that loads in the user's browswer, collects some data, then writes the data to a file on the server from which the applet was loaded.
Here is what I have managed to accomplish (using my Win98 comp and Unix server):
from just loading the applet on my computer and using relative file name to write - it made a file on my desktop (not the right place) but with the correct information
on my comp and using absolute windows file name - it made the file in the right place and with correct information
from trying the applet over the web on a server that allows you to write to files using both relative and absolute file names - acted dead when I pushed the button that would make it write to a file, and it didn't execute the "catch."
I really want this to work since I want the applet to be the user interface and the applet is preferred to javascript or something else because of the nature of what I'm doing. Also, we were going to use a SQL database. I know Java has an interface with SQL but could I get my applet to communicate with our SQL database on the server directly or are we going to have to make another script for it to go through?
thanks

The following is a duplicate posting in reponse to similar question:
http://forum.java.sun.com/thread.jsp?forum=4&thread=200482&start=0&range=30#735223
In short, you cannot write to a server without help from servier-side software such as a servlet, cgi, ASP, etc.
If you go with something like an Oracle database on your server, it's a non-issue because the seucirty aspects are taken care of for you.
V.V.

Similar Messages

  • Java applet writes to file on client, no signing necessary

    Hi,
    I wonder if this is a feature or bug:
    I download and execute in my browser an unsigned applet/jar myCharts.jar from server. The applet references classes from package org.jfree.chart, which are not packed in myCharts.jar downloaded from server, but are locally stored on client in jre/lib/ext/jfreechart.jar (and therefore JVM running the applet loads and uses these local classes from local jar).
    The applet can write the file to client disk without any problem using classes from locally loaded jfreechart.jar. If I merge both jars into a big one and load it through network, file write access is forbidden.
    I am using JRE 1.5.0.3 for Windows and default java_policy file with 2      permissions added:
    permission java.lang.RuntimePermission "accessDeclaredMembers";
    permission java.lang.reflect.ReflectPermission "suppressAccessChecks";
    Is it a bug, or feature ?
    According to my opinion these 2 permissions should not result in applet ability to write files using locally loaded classes.
    Thanks for your answer
    Martin

    The following is a duplicate posting in reponse to similar question:
    http://forum.java.sun.com/thread.jsp?forum=4&thread=200482&start=0&range=30#735223
    In short, you cannot write to a server without help from servier-side software such as a servlet, cgi, ASP, etc.
    If you go with something like an Oracle database on your server, it's a non-issue because the seucirty aspects are taken care of for you.
    V.V.

  • How to over write a file on server using Dataset

    Hello Experts,
    Iu2019ve trying to write a code to fetch data in my program and create a file on server. My program work fine. However every time I run my program it append data at the end of the tile which it created 1st time. I donu2019t want this to happen. I want to new record to print on this file or in other words I want it to over write the file. Here is my code of dataset part.
    open dataset file for appending in text mode encoding default.
    if sy-subrc ne 0.
      write:/ 'File Opening/Creation Error'.
        exit.
    endif.
    loop at ivbrk.
      clear record.
        move ivbrk-headr to record+1(1).
        move ivbrk-vbeln to record+3(10).
        move ivbrk-waerk to record+15(5).
        move ivbrk-knumv to record+22(10).
        move ivbrk-fkdat to record+34(8).
        move ivbrk-kunrg to record+43(10).
        move ivbrk-kunag to record+54(10).
          transfer record to file.
        loop at ivbrp where vbeln = ivbrp-vbeln.
         clear items.
          move ivbrp-items to items+1(1).
          move ivbrp-posnr to items+3(6).
          move ivbrp-fkimg to items+11(13).
          move ivbrp-vrkme to items+25(3).
          move ivbrp-meins to items+30(3).
          move ivbrp-ntgew to items+34(15).
          move ivbrp-brgew to items+50(15).
          move ivbrp-gewei to items+66(3).
            transfer items to file.
        endloop.
    endloop.
    close dataset file.
    Can please somebody tell me what change I should make to over write on this file?
    Thanks a lot in advance.
    Moderator message - Please use code tags around your code
    Edited by: Rob Burbank on Jan 12, 2010 5:08 PM

    Hey zero:
    open dataset file for appending in text mode encoding default.
    Probably because you're opening it for appending.
    Rob

  • Write to file on server from app

    Am trying to write to a file on server from an application like this:
    java.net.URL url = new java.net.URL("http://www.rikif.dk/test.txt");
    URLConnection conn = url.openConnection();
    conn.setUseCaches(false);
    conn.setDoOutput(true);
    PrintStream out =
    new PrintStream(conn.getOutputStream());
    out.print("sdfsdf");
    out.flush();
    out.close();
    But nothing happens. What am I doing wrong?

    No exceptions.. "Unlike other output streams, a PrintStream never throws an IOException".
    You can write a file through HTTP into a web server? It does not make sense really.. is the file writable in the web server?
    And why be writable - anyone would be able to write it then.
    You can achieve that through sockets. A java program on the remote machine (playing the role of a server) would accept data through a socket from the clients, and would write the files itself.. without need of web servers.
    You can use a tomcat server, and use a servlet, again to accept data and write the files itself.
    ..or?

  • How to read and write to file on server

    can any body tell how to read or write to a file on server, like where do i keep the file and what does the path look like......on server
    stand alone i am reading and writing into file but when it comes to server i am confused how it works...i mean the path
    thank you

    The Path needs to be absolute:
    For example in Unix it would look like:
    /usr/paz/Test.txtIn Windows it would look like:
    C:/Paz/Test.txtHope this helps.
    Thanks and regards,
    Pazhanikanthan. P

  • Security manager - applet - write/read files

    Hi.
    I've been trying to built a SecurityManager to allow my java applet to construct a file (*.txt or *.doc) on the server (webhosting provider) it came from. Unfortunately when I use the setSecurityManager method to set my Security Manager as the default Security Manager for that specific applet, the applet throws a SecurityException. It wouldn't allow me to change the Security Manager.
    I want to change the default Security Manager so that my applet can have permission to read and write to the specified file (*.txt or *.doc). I don't want to save any kind of files on the host computer even if I can do that, I only require to save my file (*.txt or *.doc) to the computer from were the applet's classes came from.
    Thank you!

    If there is a security manager already installed, this method first calls the security manager's checkPermission method with a RuntimePermission("setSecurityManager") permission to ensure it's ok to replace the existing security manager. This may result in throwing a SecurityException. Thus I think that you need to grant the setSecurityManager permission to your current SecurityManager to be able to replace it.

  • Applet write file on coming server without servlet

    Hi, I have an applet that needs to write a new file on the server that's LOADED FROM. Here are my questions:
    1) can the applet write this file WITHOUT using a servlet on the server side?
    2) if it's possible, could someone send me an example to explain how to do it?
    Thanks in advance, have a nice day

    1) can the applet write this file WITHOUT using a
    servlet on the server side?No,it can't. Well, on the server is not necessary to
    have a java servlet but you should have "something"
    that can receive your data, understand it and save it.
    A small PHP script is enough.
    Hope this help

  • How  applet write file in local system by URL instead of FileOutputStream()

    hi,
    how can applet write a file in local system through URL instead of FileOupStream()
    plz.....plz.....plz......
    URL url = new URL(" file://c:/temp.txt");
    in this url how applet can write
    plz....

    URL uses http to cummunicate, this means you can send and receive data using the http
    protocol.
    The OS doesn't do anything with this, you need a http server to interpret these messages
    and take appropriate action (with server side script or CGI).
    So if the client has a http server installed and has server side script thad does
    something with your http request (that's what a url does) than it is possible.
    Since both having a http server , server side script and or CGI have nothing to do with
    signed applets I will not answer your question here.
    But the mail reason I won't answer it is because it makes no sence to use a URL to write
    to the local file system.

  • Applet: update file on server

    Hi Forum,
    Following is the code in an applet to update file on server.
    Why does the following code is not doing any updation to the server file?
    Any reply will be appreciated.
    protected void SaveFile() {
    try {
    URL url = new URL("Http://uptsrv/draw/Sample.txt");
    //URL url = new URL(getCodeBase(),filename);
    URLConnection urlCon = url.openConnection();
    this.showStatus(" Saving... " + url.getPath());
    urlCon.connect();
    urlCon.setDefaultUseCaches(false);
    urlCon.setDoOutput(true);
    urlCon.setDoInput(true);
    PrintWriter stream = new PrintWriter(urlCon.getOutputStream());
    stream.print("Bharath");
    stream.close();
    stream=null;
    catch(MalformedURLException mue){
    //initDrawing();
    showStatus("Error: " + mue);
    catch (IOException e) {
    //initDrawing();
    showStatus("Error: " + e);
    Regards,
    Bharath Kumar A
    Software engineering tools Team
    Honeywell India Software operations Pvt. Ltd.
    151/1, doraisani palya,
    Bannergatta Road
    Bangalore - 76
    India
    Email: [email protected]

    check this link
    http://java.sun.com/docs/books/tutorial/networking/urls/readingWriting.html
    also check the directory and file permissions of ur Http Sever .
    I think u r going the wrong way . i m not sure that u can write a string to a file using URL connection
    Renjith

  • 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...

  • How to write file to server side?

    hello,
    Could anyone pls help me...
    I just want to see an example how can I write to a file that is placed at the server(save place as the applet).
    p.s. I have been successfully read a file from there...
    Suppose I have signed the applet (self-signed), anymore security problem I need to pay attention to?
    Thanks a lot!!

    hi mandy, from the applet u can send the file to be written into the server to a servlet running in server and the servlet can in turn write the file into the servlet. by applet - servlet communication, u can easily read and write files to the server.

  • Write to file??? looking for a solution to write file to the server

    Dear all,
    Since most browsers forbid all file access, so is there is another way to write file to server in applet??? or is there an alternative using combination of JSP??
    Thank you for your attention,
    Dan

    If you have access to the server you are writing the file to then you could have your applet collect information and send it to the server in a form. Then write a bean or other class that handles it and writes it to the server.

  • Create a new file on server from an applet

    Hello!
    I 'm trying to create a text file on server from an applet, i have permissions to write on server and i'm running in apache, my code is
    public void write () {
    try{
    URL url = new URL("http://localhost/bnm/hello.txt");
    URLConnection urlcon = url.openConnection();
    urlcon.setDoOutput(true);
    urlcon.setUseCaches(true);
    PrintWriter pt = new PrintWriter
    (new OutputStreamWriter (urlcon.getOutputStream()));
    String str = new String(URLEncoder.encode("this is output applet ")) ;
    pt.print(str);
    pt.flush();
    catch(Exception e)
    e.printStackTrace();
    The result is nothing, the file isn�t created, but the code don't throw exceptions.
    Ah! in other example, i can read a file of server fro m the applet, the problem is to write
    Anybody, knows the matter??
    Excuse my poor english :P
    Thanks for all.

    I had the same needs and didn't know whether this was possible, due to applets security restriction. So I searched the Web and found some contradictory information. I will explain what I think is the situation, to give you an answer, but also so that other people can tell me whether I understood correctly.
    1) Unless you sign it, an applet cannot write files directly, either client-side or server-side. All what it can do to access a file server-side (except .jar files ?) is opening a http connection, which allows only to retrieve data. When I try to run code such as yours, I get this exception :
    java.net.UnknownServiceException: protocol doesn't support output
         at java.net.URLConnection.getOutputStream(URLConnection.java:679)
    2) As Ares_Man points out, what it can do is opening a http connection not directly with the file you want, but with a server-side script (JSP, PHP, CGI,...) which will be allowed to write files on the server. You can use POST or GET parameters to pass to the script what you are going to write.
    This simple code worked for me (it executed the script toto.php):
              try{
                   URL toto=new URL(getCodeBase(),"toto.php");
                   InputStream f=toto.openStream();
                   f.close();
              catch(Exception e){
                   e.printStackTrace();
    Probably it's a good idea to do a URLConnection.setCache(false) though, to be sure that the script toto.php will be executed.
    3) I don't know how you can pass serialized objects as parameters. So if more than text informations are to be written, I would tend to make the script store them into a database instead of files. That way, you could pass any SQL query as parameter, maybe along with a password parameter for security. I don't know whether this is secure enough.

  • Copy a .swf file from server side to client using signed applet

    Hello All,
    I already have my applet signed and its working pretty well. However I want to know how can I import a .swf file into clients machine. The .swf file initially is on server side, my applet checks whether this .swf file exists already on client machine. If not it copies it to his machine.
    I know how to chk if the file already exits on client machine but I am not sure how to copy this .swf file to his machine if its missing.
    May be I need to set some input buffers from server side and then copy them to his machine.
    Can some one throw some light on this issue ??

    Hello to all Java Code Masters out thr,
    I am trying to copy a .swf file from server side to client side, however I am unsuccessful in writing the correct data. By correct data I mean that , the data does gets saved on the client side in the .swf file, and the size of the .swf file on client side is as expected, but some how I don't know why the data is not the same as expected.
    I tried opening up both the swf file, one which is on server side and the other which is on client side. And both looked different in the notepad.
    When I opens up the client side .swf file on browser it shows nothing while the .swf file on server side worked fine.
    Here is a snap shot of the two .swf files when opened in notepad:
    clientside.swf
    &#22339;&#2131;&#51395;&#40056;&#48612;&#28681;&#56220;&#6234;&#31352;&#65363;&#27474;&#26039;&#46793;&#52076;&#11698;&#45679;&#32228;&#9617;&#45643;&#52076;&#54002;&#56237;&#62930;&#57181;&#27635;&#46965;&#48804;&#30062;&#60407;&#31086;&#2937;&#37359;&#28873;&#49741;&#8252;&#10112;&#503;&#8501;&#16164;&#43397;&#16140;&#10313;&#8264;&#537;&#13737;&#16956;&#43411;&#586;&#4917;&#43544;&#22918;&#4216;&#49632;&#40179;&#64495;&#64206;&#44335;&#61334;&#19077;&#57113;&#61099;&#53246;&#52863;&#52855;&#52985;&#32246;&#63967;&#27542;&#13055;&#32611;&#52219;&#26476;&#56728;&#25064;&#57340;&#63580;&#65317;&#56023;&#32706;&#57446;&#19865;&#24183;&#40928;&#65057;&#61684;&#25313;&#64294;&#45864;&#44950;&#25919;&#7115;&#8035;&#44004;&#31973;&#18921;&#32575;&#18967;&#25451;&#63915;&#44668;&#30262;&#32651;&#11230;&#60116;&#21241;&#51902;&#30302;&#2462;&#38913;&#38887;&#2904;&#47227;&#11350;&#25775;&#35978;&#25879;&#38313;&#61967;&#15065;&#8627;&#33840;&#11456;&#12040;&#52418;&#33633;&#6640;&#63050;&#65270;&#39008;&#42184;&#40462;&#49876;&#16324;&#15399;&#60051;&#62263;&#26562;&#19076;&#47084;&#16512;&#51385;&#58710;&#13280;&#42314;&#13071;&#55199;&#17948;&#14772;&#61464;&#8985;&#9032;&#16254;&#42612;&#16367;&#47121;&#16212;&#60451;serverside.swf
    CWS�� x���     p��ZxzS�Rk�e��l��-o��}�%K�l�������]��ku���nu��nyy���pM�< �'�5!$����I
    (H �
    5<B
    ��J5��Yx��������/����J������w����}���
    k�2c��lg���a��\�%��serverside.swf is what I expect to be saved, but clientside.swf is what i get.
    Below is a code snippet which I am trying :
      public void writeswftoclient(String swfcontent) {
        String userHome = System.getProperty("user.home" );
        String ImoracleDirectory = userHome + "\\MyFolder";
        File fdirectory = new File(ImoracleDirectory);
        if(!fdirectory.isDirectory()) {
          fdirectory.mkdir();
        String playlist = ImoracleDirectory + "\\clientside.swf";
        File fplaylist = new File(playlist);
        try {
          Writer output = null;
          output = new BufferedWriter(new FileWriter(fplaylist,true));
          *System.out.println(swfcontent);*
          *output.write(swfcontent);*
          output.close();
        catch (Exception e) {
          System.out.println("Cannot create or write to the playlist");
      }In above code I am trying to write the string swfcontent, which contains the data shown above in serverside.swf, to clientside.swf.
    Interesting thing is that I am doing System.out.println(swfcontent); just before writing the data to clientside.swf using output.write(swfcontent);. And System.out.println does print the write data on the java console. However I dont know out of what reason the data doesnt get written correctly on the client's computer.
    Kindly help me in this plzzzzzzzzzz.

  • Read PDF Formatted Spool and write PDF File to Application Server

    Hi Experts,
    After ECC 6.0, HR-W2 and W2C Form Spools are getting generated in PDF format.
    We have a requirement wherein we want to read the PDF Spool Programatically and write the PDF file to Application server (Using OPEN DATASET and CLOSE DATASET)
    PARAMETERS : p_spono LIKE tsp01-rqident.
    DATA: pdf_data type FPCONTENT.
    types: lt_pdf_table(1000) type x.
    data:  l_pdf_data type standard table of lt_pdf_table,
           l_pdf_line type lt_pdf_table,
           l_offset type i,
           l_len type i,
           p_file(100) VALUE '\sapout\DVH\pdf2.pdf'.
    *Read the spool content
    CALL FUNCTION 'FPCOMP_CREATE_PDF_FROM_SPOOL'
        EXPORTING
             i_spoolid = p_spono
             i_partnum = '1'
        IMPORTING
               e_pdf = pdf_data
    *         e_pdf_file = file
        EXCEPTIONS
             ads_error = 1
             usage_error = 2
             system_error = 3
             internal_error = 4
        OTHERS = 5.
    * Modify the spool  contents to prepare internal table
      l_len = xstrlen( pdf_data ).
      while l_len >= 1000.
        l_pdf_line = pdf_data+l_offset(1000).
        append l_pdf_line to l_pdf_data.
        add 1000 to l_offset.
        subtract 1000 from l_len.
      endwhile.
      if l_len > 0.
        l_pdf_line = pdf_data+l_offset(l_len).
        append l_pdf_line to l_pdf_data.
      endif.
    * GUI DOWNLOAD Works Fine
    * Now pdf contents is ready , lets store in local PC
    *CALL FUNCTION 'GUI_DOWNLOAD'
    *  EXPORTING
    *   filename                        = 'C:\Documents and Settings\Desktop\shital.pdf'
    *   filetype                        = 'BIN'
    *  TABLES
    *    data_tab                        = l_pdf_data.
    OPEN DATASET p_file FOR OUTPUT IN BINARY MODE.
    IF sy-subrc <> 0.
      MESSAGE ID '00' TYPE 'E' NUMBER '398' WITH 'sy-subrc:' sy-subrc
              ' Error opening file:'(Z03) p_file.
    ENDIF.
    LOOP AT l_pdf_data INTO l_pdf_line.
      TRANSFER l_pdf_line TO p_file.
    ENDLOOP.
    CLOSE DATASET p_file.
    IF sy-subrc <> 0.
      MESSAGE ID '00' TYPE 'E' NUMBER '398' WITH 'sy-subrc:' sy-subrc
              ' Error closing file:'(Z04) p_file.
    ENDIF.
    Currently as you can see I have commented out GUI_DOWNLOAD Function Module, But it works perfect when I try to Download file to Local Desktop.
    But when I try to pass the same Contents to Application server file and then try to open it by downloading file then it opens BLANK pdf file.
    As per requirements I should be able to write the file correctly on Application server and If I dowload it from there it should open PDF file correctly.
    Let me know if you require further details about the issue.
    Regards
    Shital
    Edited by: shital phadake on Apr 8, 2009 9:39 PM

    Thanks Selçuk for your reply and taking time for understanding the Issue,
    I went thru Functionality of the program you suggested but dont think it matches my requirement.
    Regards
    Shital

Maybe you are looking for