Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 8 of 8

Thread: Applet writing to an http server.

  1. #1
    Member
    Join Date
    Sep 2013
    Posts
    102
    Thanks
    38
    Thanked 0 Times in 0 Posts

    Default Applet writing to an http server.

    I am trying to write to an http server, but nothing happens. I can read from the file, I just cannot write to it and no errors are thrown. I do not know how to proceed.

    Specifically, I have a text file on my server, and I can read from it (the text file already has content), but I cannot write to it. And, no exceptions are thrown.
     
        url = new URL("http://kajl-ig.com/txt.txt"); 
        urlConn = url.openConnection(); 
        urlConn.setDoInput(true); 
        urlConn.setDoOutput(true); 
        urlConn.setUseCaches(false); 
        BufferedWriter  bw = new BufferedWriter(new OutputStreamWriter(urlConn.getOutputStream()));
        String s = "TEST Successfull!"; 
     
    	bw.write(s); // doesn't work
    	bw.close();
     
    	BufferedReader br = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));
    	System.out.println(br.readLine()); // works
      } 
     
      catch (MalformedURLException mue) { System.out.println("MUE");
      } 
      catch (IOException ioe) { System.out.println("IOE");
      }

    That was my initial code, here is another API I tried:

    URL                url; 
        URLConnection      urlConn; 
        DataOutputStream   dos; 
        DataInputStream    dis;
     
        url = new URL("http://kajl-ig.com/txt.txt"); 
        urlConn = url.openConnection(); 
        urlConn.setDoInput(true); 
        urlConn.setDoOutput(true); 
        urlConn.setUseCaches(false); 
        BufferedWriter  bw = new BufferedWriter(new OutputStreamWriter(urlConn.getOutputStream()));
        String message = "TEST Successfull!"; 
     
     
        dos = new DataOutputStream (urlConn.getOutputStream());  
        dos.writeBytes(message); 
        	dos.flush();
    	dos.close();
     
        dis = new DataInputStream(urlConn.getInputStream()); 
        String s = dis.readLine(); 
        dis.close(); 
       System.out.println(s+" "+dos.size());
     
      } // end of "try"
     
      catch (MalformedURLException mue) { System.out.println("MUE");
      } 
      catch (IOException ioe) { System.out.println("IOE");
      }

    The second code, I got from some random website, and I was desperate so I tried it. I am not sure what the
    urlConn.setRequestProperty (String, String);
    method does, so I removed it and it reads fine it just cannot write.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Applet writing to an http server.

    I can read from the file, I just cannot write to it
    I have a text file on my server, and I can read from it (the text file already has content), but I cannot write to it.
    Are you asking about How would your code write to a file on the server? That would be controlled by the code on the server.
    If you don't understand my answer, don't ignore it, ask a question.

  3. The Following User Says Thank You to Norm For This Useful Post:

    KAJLogic (July 7th, 2014)

  4. #3
    Member
    Join Date
    Sep 2013
    Posts
    102
    Thanks
    38
    Thanked 0 Times in 0 Posts

    Default Re: Applet writing to an http server.

    I was under the impression I could write to any http server (via a basic CGI). I am using hostgator, and I can do file transfers via FTP. So, this should reproduce that essentially right?

  5. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Applet writing to an http server.

    My understanding of a server is that it will respond to requests. The client sends a request and the server will do what it is programmed to do.
    What kind of server are you testing with?
    If you don't understand my answer, don't ignore it, ask a question.

  6. The Following User Says Thank You to Norm For This Useful Post:

    KAJLogic (July 7th, 2014)

  7. #5
    Member
    Join Date
    Sep 2013
    Posts
    102
    Thanks
    38
    Thanked 0 Times in 0 Posts

    Default Re: Applet writing to an http server.

    I have very limited access to their gateway.

  8. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Applet writing to an http server.

    I have very limited access to their gateway.
    Sorry, I don't understand what that means.

    How is that related to your problem?

    Have you tried testing with a localhost server?
    If you don't understand my answer, don't ignore it, ask a question.

  9. The Following User Says Thank You to Norm For This Useful Post:

    KAJLogic (July 7th, 2014)

  10. #7
    Member
    Join Date
    Sep 2013
    Posts
    102
    Thanks
    38
    Thanked 0 Times in 0 Posts

    Default Re: Applet writing to an http server.

    Yes, it has to be a server side issue. When I said gateway I was referring to a gateway interface for retrieving or accessing their SQL.

  11. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Applet writing to an http server.

    Do you have any more questions about this?
    If you don't understand my answer, don't ignore it, ask a question.

  12. The Following User Says Thank You to Norm For This Useful Post:

    KAJLogic (July 7th, 2014)

Similar Threads

  1. session management in apache http server
    By manjunath_kotagi in forum Web Frameworks
    Replies: 0
    Last Post: October 17th, 2013, 12:21 AM
  2. Simple HTTP-Server
    By v1per1987 in forum Java Networking
    Replies: 2
    Last Post: July 27th, 2012, 01:17 PM
  3. One-Shot-HTTP-Server
    By v1per1987 in forum Java Networking
    Replies: 3
    Last Post: July 24th, 2012, 04:35 PM
  4. Applet Not Writing to FTP
    By jtd200 in forum Java Networking
    Replies: 9
    Last Post: January 13th, 2012, 12:25 PM