Results 1 to 12 of 12
  1. #1
    tanjo3 is offline Member
    Join Date
    Jan 2011
    Posts
    9
    Rep Power
    0

    Default Writing to site??

    Hi, I'm quite new to Java but I understand the fundamental concepts. I'm trying to write a program which will be able to write data to a text file online. How do I do that? I've read this website and I've got it to read; it's the writing I don't understand. Could someone help me write some code to write to a file online? Thanks!
    Last edited by tanjo3; 01-30-2011 at 07:57 PM.

  2. #2
    baloda is offline Member
    Join Date
    Nov 2010
    Location
    New Delhi
    Posts
    50
    Rep Power
    0

    Default

    u can use code mentioned below in jsp or servlet to write data to a web page(abc.html)


    File fFile = new File("c:\\sld32" + "abc.html");

    writeFile(fFile);

    hope this will help u.

  3. #3
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default

    You could do it several ways, it depends on what kind of access you have to the server. If you only have http access to it, then a JSP page would be a very simple way to do it. You can pass data via parameters in http or do an http post if its a lot of data. If you have ftp or other access, there are ways of connecting that way too.

    However, if you have open ports, you can open a server socket on the host, and connect to it with a regular socket from the client and pass any data you want back and forth using Object Serialization.

  4. #4
    tanjo3 is offline Member
    Join Date
    Jan 2011
    Posts
    9
    Rep Power
    0

    Default

    Well, I made a Webs site. What kind of access is that?

  5. #5
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default

    http. JSP is probably the easiest way if you own the server hardware, or have direct access to it. However, to run it, you'll need application server software like jetty or glassfish. If you don't have control over the server, you won't be able to install those. Your only other option in that case would be through PHP or something similar, as most webservers (even locked down ones) give you php access.

  6. #6
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default

    P.S. If this is webspace like EC2 from amazon or the like, you have full control. You can run anything you want on any port and are not required to stay in the bounds of http. But many cheapo services and even some paid ones, don't give you that kind of access.

  7. #7
    tanjo3 is offline Member
    Join Date
    Jan 2011
    Posts
    9
    Rep Power
    0

    Default

    Right, well I probably don't have full control and I don't know PHP.

  8. #8
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default

    Well, then now would be a great time to look up a PHP tutorial huh? Judging by your comments, I have a feeling you have a whole stack of research ahead of you. I would look into HTTP, REST (also an http protocol), PHP, and Sockets for starters. You can't just type in a url an write a file - if it was that easy, I could just put files on any website.

    Servers that host sites have limited access for a reason. Because of this, things like REST were created. Find out what you can do with your space - If its just webspace with and FTP address, then the answer is not much. Even so, I would find out what type of server side scripting they support (PERL, PHP, ColdFusion, Python, JSP, Rails, Grails, etc...). All of these server side languages/frameworks would do what you want, but your server must support them!

  9. #9
    tanjo3 is offline Member
    Join Date
    Jan 2011
    Posts
    9
    Rep Power
    0

    Default

    lol I definitely have work ahead. Wish me luck!

  10. #10
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default

    Good luck! Let us know if you need more help, I'll be happy to explain something if I can!

  11. #11
    tanjo3 is offline Member
    Join Date
    Jan 2011
    Posts
    9
    Rep Power
    0

    Default

    Since I'm storing data to a site, could I use MySQL?

  12. #12
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default

    If the server has MySQL, you can def. access it with java. However:
    Giving MySQL outside world access is generally a bad idea from a security and design perspective. What normally happens, mysql is on the server, but only applications running on the server have access to it.

    A client would connect to a server application, which in turn puts things in the database. If the user wants to get something from the database, the server side web applications reads it and displays it to the user. This way you have a separation between data storage, data access, and data display.

    This is a basic design pattern called Model View Controller (MVC). Frameworks like Ruby on Rails or the java version, Groovy on Grails use this pattern inherently. It has many advantages, and is worth the effort to learn, however, if you are a beginner, its a bit of a learning curve.

    PHP and the like give you a simpler means to simple make a web page with some special code in it - it allows you to make loops, sql queries, conditional logic, etc... and then the server simply strips it out and returns a formatted webpage. This is a bit easier to pick up. JSP is basically the same thing, but written in java. It does however require a java application server, which you probably don't have. PHP is pretty common, most of this forum is written with it.

Similar Threads

  1. My new site
    By sijitg in forum Reviews / Advertising
    Replies: 0
    Last Post: 10-05-2010, 09:59 AM
  2. Im a new member of this site
    By orthoritz in forum Introductions
    Replies: 4
    Last Post: 06-08-2010, 04:55 PM
  3. Replies: 1
    Last Post: 02-27-2010, 01:29 AM
  4. What does rep power mean in our site?
    By makpandian in forum New To Java
    Replies: 12
    Last Post: 06-27-2009, 05:42 PM
  5. Hello, everyone. I am newbie to this site
    By baiwen in forum Introductions
    Replies: 1
    Last Post: 03-28-2009, 05:43 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •